/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 * Wallpaper.c
 *
 * Project:
 * --------
 *   MAUI
 *
 * Description:
 * ------------
 *   This file is intends for wallpaper
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/***************************************************************************** 
* Include
*****************************************************************************/
/*  Include: MMI header file */
#include "MMI_features.h"
#include "FileMgrSrvGProt.h"
#include "SettingProt.h"
#include "WPSSProtos.h"
#include "drm_def.h"
#include "drm_gprot.h"
#include "Mdi_include.h"

#include "PhoneSetup.h"
#include "PhoneSetupGprots.h"
#include "FileMgrGProt.h"
#include "Menucuigprot.h"
#ifdef __MMI_FILE_MANAGER__
#include "Filemgrcuigprot.h"
#endif 

#ifdef __MMI_AVATAR__
#include "AvatarGprot.h"
#endif

#ifdef __MMI_DUAL_SIM_MASTER__
#include "MTPNP_AD_master_if.h"
#endif /* __MMI_DUAL_SIM_MASTER__ */

#include "Conversions.h"
#include "SimDetectionGprot.h"
#include "IdleAppDef.h"

#include "USBDeviceGprot.h"
#ifdef __MMI_USB_SPLIT_SUPPORT__
#include "USBSrvGprot.h"
#endif

#if defined(__MMI_OP11_HOMESCREEN_0301__) || defined(__MMI_OP11_HOMESCREEN_0302__)
#include "HomeScreenOp11V32Setting.h"
#endif

#ifdef __MMI_VUI_HOMESCREEN__
#include "vapp_hs_wallpaper_cfg.h"
#endif

#ifdef __MMI_FILE_MANAGER__
#define FMGR_DEFAULT_FOLDER_SETTINGS   "Settings"
#endif 

#if defined(SYNCML_DM_SUPPORT) && defined(__DM_LAWMO_SUPPORT__)
#include "dmuigprot.h" /* For DM lock check */
#endif /* defined(SYNCML_DM_SUPPORT) && defined(__DM_LAWMO_SUPPORT__) */
#include "SimCtrlSrvGprot.h"
#include "BootupSrvGprot.h"

/* auto add by kw_check begin */
#include "wgui_categories_list.h"
#include "MMIDataType.h"
#include "kal_non_specific_general_types.h"
#include "mmi_phnset_dispchar.h"
#include "mmi_rp_file_type_def.h"
#include "gui_config.h"
#include "gdi_const.h"
#include "gdi_datatype.h"
#include "mmi_frm_scenario_gprot.h"
#include "mmi_rp_srv_wallpaper_def.h"
#include "custom_mmi_default_value.h"
#include "PhoneSetupResList.h"
#include "mmi_rp_app_phonesetting_new_def.h"
#include "CustDataRes.h"
#include "kal_release.h"
#include "DebugInitDef_Int.h"
#include "GlobalResDef.h"
#include "mmi_frm_events_gprot.h"
#include "AlertScreen.h"
#include "wgui_categories_util.h"
#include "GlobalConstants.h"
#include "wgui_categories_idlescreen.h"
#include "wgui_include.h"
#include "wgui_categories_multimedia.h"
#include "mmi_frm_input_gprot.h"
#include "gui_typedef.h"
#include "MMI_common_app_trc.h"
#include "kal_trace.h"
#include "nvram_common_defs.h"
#include "mmi_frm_nvram_gprot.h"
#include "mmi_frm_mem_gprot.h"
#include "app_buff_alloc.h"
#include "Unicodexdcl.h"
#include "FileMgrType.h"
#include "mmi_frm_history_gprot.h"
#include "string.h"
#include "gdi_include.h"
#include "fs_func.h"
#include "fs_type.h"
#include "fs_errcode.h"
#include "mmi_rp_srv_phnset_onoff_def.h"
#include "TimerEvents.h"
#include "mmi_frm_timer_gprot.h"
#include "gui_data_types.h"
#include "FileMgrResDef.h"
#include "wgui_categories_popup.h"
#include "custom_events_notify.h"
#include "wgui.h"
#include "UcmSrvGprot.h"
#include "stdio.h"
#include "stack_config.h"
#include "mmi_rp_srv_screensaver_def.h"
#include "CustMenuRes.h"
/* auto add by kw_check end */
#include "PhnsetProt.h"
#include "mmi_rp_app_mainmenu_def.h"

#ifdef __MMI_DSM_NEW__
#include "mrp_include.h"
#endif
/***************************************************************************** 
* External Function
*****************************************************************************/

/***************************************************************************** 
* Local Variable
*****************************************************************************/
/* Store END key handler function pointer */
/* When previewing the user define wallpaper & Screen saver */
/* Press END key shall to release file path buffer and execute stored END key handler */
FuncPtr phnset_wpfp = NULL;
static PS8 error_str_ptr;
static U8 wp_item_amount;
static FuncPtr CallbackWpSsLSK = NULL;
static PU8 file_path_buf;
#ifdef __MMI_FILE_MANAGER__
static MMI_BOOL save_cache_flag = MMI_FALSE;
#endif

/***************************************************************************** 
* Global Variable
*****************************************************************************/
MMI_ID_TYPE idle_screen_wallpaper_ID;
MMI_ID_TYPE idle_screen_cache_id;

#ifndef __MMI_FILE_MANAGER__
S8 *idle_screen_wallpaper_name_original;
S8 *idle_screen_screensaver_name;
S8 *idle_screen_wallpaper_name;
S8 *idle_screen_cache_name;
#else /* __MMI_FILE_MANAGER__ */
/*
PHNSET_WPSS_FILENAME_STRUCT phnset_wpss_filename;
*/
mmi_phnset_wp_ss_pwrdisp_common_filename_struct g_phnset_wallpaper_actual_filename;
extern mmi_phnset_wp_ss_pwrdisp_common_filename_struct g_phnset_screensaver_actual_filename;

const U16 PHNSET_PREDEFINED_WP_PATH_JPG[] = L"Z:\\@WPCACHE\\UserWP.JPG\0";
const U16 PHNSET_PREDEFINED_WP_PATH_PBM[] = L"Z:\\@WPCACHE\\UserWP.PBM\0";
const U16 PHNSET_PREDEFINED_WP_PATH[] = L"Z:\\@WPCACHE\\";

U8 phnset_wp_default_file[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];  
U8 phnset_ss_default_file[(SRV_FMGR_PATH_MAX_LEN + 1) * 2]; 

const U8 PHNSET_DEFAULT_WP_PATH_1_path[] = "Settings\\UserWP_1";
const U8 PHNSET_DEFAULT_WP_PATH_2_path[] = "Settings\\UserWP_2";
const U8 PHNSET_DEFAULT_SS_PATH_1_path[] = "Settings\\UserSS_1";
const U8 PHNSET_DEFAULT_SS_PATH_2_path[] = "Settings\\UserSS_2";

U8 PHNSET_DEFAULT_WP_PATH_1[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
U8 PHNSET_DEFAULT_WP_PATH_2[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
U8 PHNSET_DEFAULT_SS_PATH_1[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
U8 PHNSET_DEFAULT_SS_PATH_2[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
/*
PHNSET_WPSS_FILENAME_STRUCT phnset_wpss_default_file_1;
PHNSET_WPSS_FILENAME_STRUCT phnset_wpss_default_file_2;
*/
mmi_phnset_wp_ss_pwrdisp_common_filename_struct g_phnset_wallpaper_default_file_1;
mmi_phnset_wp_ss_pwrdisp_common_filename_struct g_phnset_wallpaper_default_file_2;

extern mmi_phnset_wp_ss_pwrdisp_common_filename_struct g_phnset_screensaver_default_file_1;
extern mmi_phnset_wp_ss_pwrdisp_common_filename_struct g_phnset_screensaver_default_file_2;
/* store the image id of wallpaper */
S8 *idle_screen_wallpaper_name_original = (S8 *) phnset_wp_default_file;
S8 *idle_screen_screensaver_name = (S8 *) phnset_ss_default_file;
S8 *idle_screen_wallpaper_name;
S8 *idle_screen_cache_name;

/* Dynamic alloc memory for file path buffer */
S8 *phnset_dispchar_strp = NULL;
U8 phnset_dispchar_temp[(SRV_FMGR_PATH_MAX_FILE_NAME_LEN + 1) * 2];

static S32 g_wp_ss_copy_job_id;
static phnset_wp_ss_funcptr g_phnset_wp_ss_set_callback; /* For external set wallpaper, must be NULL if set from phone setting */
static void *g_phnset_wp_ss_set_userdata;
static MMI_ID_TYPE file_copy_result_str_id;
static phnset_wpss_type_enum g_wpss_type_backup;

#ifdef __MMI_SUB_WALLPAPER__
//PHNSET_WPSS_FILENAME_STRUCT phnset_wpss_sub_filename;
mmi_phnset_wp_ss_pwrdisp_common_filename_struct g_phnset_wallpaper_sub_filename;
//S8 *idle_screen_wallpaper_sub_name = (S8 *) phnset_wpss_sub_filename.wallpaper; /* diamond, 2005/05/09 for sub-LCD wallpaper */
S8 *idle_screen_wallpaper_sub_name = (S8 *) g_phnset_wallpaper_sub_filename.filename;
#endif /* __MMI_SUB_WALLPAPER__ */ 
#endif /* __MMI_FILE_MANAGER__ */

/* Supported file type */
mmi_phnset_display_file_type_struct mmi_phnset_display_support_image_type[] = 
{
    {FMGR_TYPE_BMP, NULL},
    {FMGR_TYPE_WBMP, NULL},
    {FMGR_TYPE_WBM, NULL},
    {FMGR_TYPE_GIF, NULL},
#ifdef JPG_DECODE        
    {FMGR_TYPE_JPG, NULL},
    {FMGR_TYPE_JPEG, NULL},    
#endif         
#if defined(GDI_USING_PNG)
    {FMGR_TYPE_PNG, NULL},
#endif
#if defined(__DRM_V02__)
    {FMGR_TYPE_ODF, NULL},
#endif
#if defined(SVG_SUPPORT) && !defined(__MMI_VUI_ENGINE__)
    {FMGR_TYPE_SVG, NULL},
#endif
#ifdef M3D_MMI_SUPPORT
    {FMGR_TYPE_M3D, NULL},
#endif        
#ifdef __MMI_SWFLASH__
    {FMGR_TYPE_VIS, NULL},
    {FMGR_TYPE_IVIS, NULL},
    {FMGR_TYPE_KVIS, NULL},        
    {FMGR_TYPE_MVIS, NULL},      
#endif        
    /* End of file type */
    {FMGR_TYPE_UNKNOWN, NULL}
};

/* Sub LCD support file type */
#ifdef __MMI_SUB_WALLPAPER__
mmi_phnset_display_file_type_struct mmi_phnset_display_support_sub_image_type[] = 
{
    {FMGR_TYPE_BMP, NULL},
    {FMGR_TYPE_WBMP, NULL},
    {FMGR_TYPE_WBM, NULL},
    {FMGR_TYPE_GIF, NULL},
#ifdef JPG_DECODE        
    {FMGR_TYPE_JPG, NULL},
    {FMGR_TYPE_JPEG, NULL},    
#endif              
#if defined(GDI_USING_PNG)
    {FMGR_TYPE_PNG, NULL},
#endif
#if defined(__DRM_V02__)
    {FMGR_TYPE_ODF, NULL},
#endif
    /* End of file type */
    {FMGR_TYPE_UNKNOWN, NULL}
};
#endif

mmi_phnset_display_file_type_struct mmi_phnset_display_support_video_type[] = 
{
#if defined(__MTK_TARGET__)
#if defined(__MMI_SCREENSAVER_DISPLAY_VIDEO__) || defined(__MMI_POWER_ON_OFF_DISPLAY_VIDEO__)
#ifdef MP4_DECODE
    {FMGR_TYPE_3GP, NULL},
    {FMGR_TYPE_MP4, NULL},
    {FMGR_TYPE_MPG, NULL},
    {FMGR_TYPE_3G2, NULL},
#endif /* MP4_DECODE */ 
#ifdef MJPG_DECODE
    {FMGR_TYPE_AVI, NULL},
#endif
#ifdef __RM_DEC_SUPPORT__
    {FMGR_TYPE_RV, NULL},
    {FMGR_TYPE_RM, NULL},
    {FMGR_TYPE_RMVB, NULL},
#endif
#endif /* defined(__MMI_SCREENSAVER_DISPLAY_VIDEO__) || defined(__MMI_POWER_ON_OFF_DISPLAY_VIDEO__) */ 
#endif /* defined(__MTK_TARGET__) */         
    {FMGR_TYPE_UNKNOWN, NULL}
};

static void mmi_phnset_display_set_file_filter_by_struct(FMGR_FILTER *filter, mmi_phnset_display_file_type_struct *filter_struct);
static MMI_BOOL mmi_phnset_display_is_file_type_in_struct(U16 file_type, mmi_phnset_display_file_type_struct *filter_struct);



/***************************************************************************** 
* Global Function
*****************************************************************************/
#ifdef __MMI_WALLPAPER_ON_BOTTOM__
void wgui_set_wallpaper_change(void);
#endif 
/***************************************************************************** 
* Extern Function
*****************************************************************************/
extern U8 PhnsetGetDefEncodingType(void);
extern GDI_RESULT gdi_anim_stop_all_by_layer(gdi_handle layer);
/***************************************************************************** 
* Local Function
*****************************************************************************/
#ifdef __MMI_AVATAR__
extern void mmi_phnset_wallpaper_avatar_highlight_hdlr(void);
#endif

static U8 PhnsetConstSysWallpaperList(U8 **pSysWallpaperStrList, U16 *pSysWallpaperImgIDList, U16 *HighliteItem);
static void DispIdleScrWPBadFilePopup(void);

void mmi_phnset_save_wallpaper_to_speedup(void);

#ifdef __MMI_FILE_MANAGER__
static pBOOL phnset_waiting_receive_rsp = MMI_FALSE;    /* receive copy response or not */
static pBOOL phnset_waiting_timeout = MMI_FALSE;        /* waiting screen time out or not */
static U8 phnset_dispchar_wp_cp_file[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
static U8 phnset_dispchar_ss_cp_file[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
static S32 mmi_phnset_del_file(const WCHAR* file_path);
static void mmi_phnset_get_postfix(U8 *postfix, U8 *inBuffer);
static void mmi_phnset_get_postfix_ucs2(U8 *postfix, U8 *inBuffer);
extern void mmi_phnset_init_default_file(void);
extern void mmi_phnset_copy_wpss_check_device(void);
extern void mmi_phnset_copy_wpss_entry_waiting_entry(void);
static mmi_ret mmi_phnset_copy_wpss_waiting_leave_proc(mmi_event_struct *evt);
extern void mmi_phnset_copy_wpss_entry_waiting_exit(void);
extern void mmi_phnset_copy_wpss_rsp(void *info);
extern void mmi_phnset_get_wpss_postfix(U8 *postfix);
extern void mmi_phnset_copy_wpss_refresh_screen(void);
static U8 mmi_phnset_copy_wallpaper_screensaver(void);
static void mmi_phnset_wallpaper_set_from_menu_finished(void* userdata, U16 process_result);
static mmi_ret mmi_phnset_display_fmgr_common_proc(mmi_event_struct *param);
static U8 mmi_phnset_check_file_limit(U8* filename);
static U8 mmi_phnset_wallpaper_init_filename(PS8 filename, S32 is_short);
static mmi_ret mmi_phnset_wallpaper_preview_proc(mmi_event_struct *param);
static U8 mmi_phnset_wallpaper_prepare_folder(S16 driver);
static U8 mmi_phnset_wallpaper_check_disk(S16 driver);
static U8 mmi_phnset_wallpaper_prepare_file_path(U8 *user_file_path);
static U8 mmi_phnset_wp_ss_set_by_filename(WCHAR* filename, phnset_wp_ss_funcptr callback, void* userdata);
static U16 mmi_phnset_wp_ss_get_error_str_id(U16 error_code);
static void mmi_phnset_wp_ss_restore_para(void); 
static void mmi_phnset_wp_ss_backup_para(void);
static mmi_ret mmi_phnset_wallpaper_entry_forward_from_fmgr(mmi_event_struct *param);
#endif /* __MMI_FILE_MANAGER__ */


#if defined(__MMI_OP11_HOMESCREEN_0301__) || defined(__MMI_OP11_HOMESCREEN_0302__) || defined(__MMI_OP11_HOMESCREEN__)
static mmi_ret mmi_phnset_wallpaper_select_menu_proc(mmi_event_struct *param);
static void mmi_phnset_entry_wallpaper_select_menu(mmi_id parent_gid);
#endif

static mmi_ret mmi_phnset_wallpaper_sub_menu_entry_handler(cui_menu_event_struct *param, MMI_ID parent_gid);
static mmi_ret mmi_phnset_wallpaper_sub_menu_highlight_handler(cui_menu_event_struct *param, MMI_ID parent_gid);
static mmi_ret mmi_phnset_wallpaper_sub_menu_select_handler(cui_menu_event_struct *param, MMI_ID parent_gid);
static void mmi_phnset_init_wallpaper_menu(void);
static void mmi_phnset_wallpaper_entry_main(mmi_id parent_gid);
static mmi_ret mmi_phnset_wallpaper_main_menu_proc(mmi_event_struct *evt);
static void mmi_phnset_entry_wallpaper_sys_int(mmi_scrn_essential_struct *scrn_data);
static void mmi_phnset_entry_wpss_common_userdef_preview(mmi_scrn_essential_struct *scrn_data);
static mmi_ret mmi_phnset_copy_wpss_proc(mmi_event_struct *param);

#ifdef __DAILY_WALLPAPER__
static void mmi_phnset_entry_wallpaper_rotate(MMI_ID parent_gid);
static mmi_ret mmi_phnset_wallpaper_rotate_proc(mmi_event_struct *param);
static void mmi_phnset_wallpaper_rotate_select_handler(mmi_event_struct *param);
#endif
#if 0
/* under construction !*/
/* under construction !*/
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER__
static mmi_ret mmi_phnset_wallpaper_live_wallpaper_proc(mmi_event_struct *evt);
static void mmi_phnset_wallpaper_init_live_wallpaper(void); 
static MMI_BOOL mmi_phnset_wallpaper_set_vui_live_wallpaper_setting(U8 data);
#endif 
/*****************************************************************************
 * FUNCTION
 *  HintPhnsetWallpaper
 * DESCRIPTION
 *  This function is hint handling function
 *  for Phonesetup -> Display Character -> Wallpaper
 *  Functionality:
 * PARAMETERS
 *  index       [IN]            
 *  a(?)        [IN/OUT]        
 *  b(?)        [IN]            
 * RETURNS
 *  void
 *****************************************************************************/
void HintPhnsetWallpaper(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    PS8 p;
    U8 live_wallpaper_setting;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __MMI_VUI_HOMESCREEN__
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER__
    live_wallpaper_setting = mmi_phnset_wallpaper_get_vui_live_wallpaper_setting();
    if (live_wallpaper_setting)
	{
        cui_menu_set_item_hint(
            mmi_frm_group_get_active_id(),
            MENU_SETTING_WALLPAPER,
            (WCHAR*)GetString(STR_ID_WALLPAPER_VUI_START + live_wallpaper_setting));    	
        return;
	}
#endif
#endif
    p = PhnsetGetCurWallpaperName();
    if (p)
    {
        cui_menu_set_item_hint(
            mmi_frm_group_get_active_id(),
            MENU_SETTING_WALLPAPER,
            (WCHAR*)p);
    }
}


#ifdef __MMI_SUB_WALLPAPER__
/*****************************************************************************
 * FUNCTION
 *  HintPhnsetSubWallpaper
 * DESCRIPTION
 *  This function is hint handling function
 *  for Phonesetup -> Display -> Wallpaper
 *  Functionality:
 * PARAMETERS
 *  index       [IN]                      
 * RETURNS
 *  void
 *****************************************************************************/
void HintPhnsetSubWallpaper(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    PS8 name;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    name = PhnsetGetCurSubWallpaperName();
    if (name)
    {
        
        cui_menu_set_item_hint(
            mmi_frm_group_get_active_id(),
            MENU_SETTING_WALLPAPER_SUB,
            (WCHAR*)name);
    }
}


#endif /* __MMI_SUB_WALLPAPER__ */ 

#ifdef __DAILY_WALLPAPER__
/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_entry_wallpaper_rotate
 * DESCRIPTION
 *  Entry rotate wallpaper screen setting menu 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_entry_wallpaper_rotate(MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phnset_appcreate_menucui_create(
        parent_gid,
        GRP_ID_WALLPAPER_ROTATE,
        MENU_SETTING_WALLPAPER_ROTATE,
        mmi_phnset_wallpaper_rotate_proc);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_rotate_proc
 * DESCRIPTION
 *  Proc function for wallpaper rotate setting menu 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_rotate_proc(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 highlighted_item;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->evt_id)
    {
    case EVT_ID_CUI_MENU_LIST_ENTRY:
        highlighted_item = (PhnsetGetWallpaperRotateStatus() == MMI_TRUE) ? 0 : 1;
        mmi_phnset_init_on_off_radio_button_menu(
            GRP_ID_WALLPAPER_ROTATE,
            STR_WALLPAPER_ROTATE,
            MAIN_MENU_TITLE_SETTINGS_ICON,
            highlighted_item);
        return MMI_RET_OK;

    case EVT_ID_CUI_MENU_ITEM_SELECT:
    case EVT_ID_CUI_MENU_ITEM_TAP:
        mmi_phnset_wallpaper_rotate_select_handler(param);
        return MMI_RET_OK;
        
    case EVT_ID_CUI_MENU_CLOSE_REQUEST:
        cui_menu_close(mmi_frm_group_get_active_id());
		return MMI_RET_OK;
		
    default:
		break;
    }
    return MMI_RET_OK;    
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_rotate_select_handler
 * DESCRIPTION
 *  Select handler for wallpaper rotate setting menu 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_wallpaper_rotate_select_handler(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    cui_menu_event_struct *menucui_param = (cui_menu_event_struct*)param;
    U8 highlighted_item;
    S16 error;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    highlighted_item = (menucui_param->highlighted_menu_id == 1) ? 0 : 1;
    WriteValue(NVRAM_SET_CALENDAR_IDLESCREEN, &highlighted_item, DS_BYTE, &error);
    mmi_popup_display_simple(
        (WCHAR*)GetString(STR_GLOBAL_DONE),
        MMI_EVENT_SUCCESS,
        GRP_ID_ROOT,        
        NULL);
    mmi_frm_group_close(GRP_ID_WALLPAPER_ROTATE);    
}


/*****************************************************************************
 * FUNCTION
 *  HintPhnsetWallpaperRotate
 * DESCRIPTION
 *  This function is Hint handler for Wallpaper Rotate status
 *  Functionality: Show hint for rotate status
 * PARAMETERS
 *  index       [IN]            
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void HintPhnsetWallpaperRotate(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    PS8 hint_str;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (PhnsetGetWallpaperRotateStatus() == MMI_TRUE)
    {
        hint_str = (PS8)GetString(STR_GLOBAL_ON);
    }
    else
    {
        hint_str = (PS8)GetString(STR_GLOBAL_OFF);
    }
    cui_menu_set_item_hint(
        mmi_frm_group_get_active_id(),
        MENU_SETTING_WALLPAPER_ROTATE,
        hint_str);
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetWallpaperRotateStatus
 * DESCRIPTION
 *  This function is to query rotate status
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  T/F
 *****************************************************************************/
BOOL PhnsetGetWallpaperRotateStatus(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 status = 0x0;
    S16 error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ReadValue(NVRAM_WALLPAPER_ROTATE_STATUS, (void*)&status, DS_BYTE, &error);

    if (status == 0x0 || error != NVRAM_READ_SUCCESS)
    {
        return MMI_FALSE;
    }
    else
    {
        return MMI_TRUE;
    }
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWallPaperDailyChange
 * DESCRIPTION
 *  This function is to change wallpaper to next one in system folder
 *  Functionality: ex: Referenced by DateTimerIndication
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        
 *  b(?)        [IN]            
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallPaperDailyChange(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 curWallpaperId;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    curWallpaperId = PhnsetGetCurWallPaperIdx();
    if (curWallpaperId == 0xFF)
    {
    #ifdef __MMI_SUB_WALLPAPER__
        g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP;
    #endif 

        PhnsetRstWallpaperDefault();
        if (g_idle_context.IsOnIdleScreen)
        {
            EntryIdleScreen();
        }

        return;
    }

    if ((curWallpaperId + 1) > MAX_WALLPAPER_IMG)
    {
        curWallpaperId = 0;
    }
    else
    {
        curWallpaperId++;
    }

    PhnsetSetDisplayFromAT(curWallpaperId, MMI_PHNSET_TYPE_WP);
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetCurWallPaperIdx
 * DESCRIPTION
 *  This function is to get the current wallpaper index in gSystemWallpaperList
 *  Functionality: ex: Referenced by PhnsetWallPaperDailyChange
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        
 *  b(?)        [IN]            
 * RETURNS
 *  U8 index
 *****************************************************************************/
U8 PhnsetGetCurWallPaperIdx(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 idx = 0;
    U16 SysWpIDList[MAX_WALLPAPER_NUMBERS];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    PhnsetConstSysWallpaperList(NULL, SysWpIDList, NULL);

    for (idx = 0; idx < (MAX_SYSTEM_WALLPAPER + MAXIMUM_FULLSCREEN_FACTORY_IMAGES); idx++)
    {
        if (g_phnset_cntx_p->curtWpID == SysWpIDList[idx])
        {
            break;
        }
    }

    if (idx >= (MAX_SYSTEM_WALLPAPER + MAXIMUM_FULLSCREEN_FACTORY_IMAGES))
    {
        idx = 0xFF; /* Not Found! */
    }

    return idx;
}
#else /* __DAILY_WALLPAPER__ */ 


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetCurWallPaperIdx
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  
 *****************************************************************************/
U16 PhnsetGetCurWallPaperIdx(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 idx;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_dispchar_get_img_id(NVRAM_FUNANDGAMES_SETWALLPAPER, &(idx));
    return idx;
}

#endif /* __DAILY_WALLPAPER__ */ 


/*****************************************************************************
 * FUNCTION
 *  PhnsetConstSysWallpaperList
 * DESCRIPTION
 *  This function is to construct wallpaper system folder list,
 *  for Setting->Phonesetup->IdleScreenDisplay->Wallpaper (->Fix) ->System
 * PARAMETERS
 *  pSysWallpaperStrList        [IN]            
 *  pSysWallpaperImgIDList      [?]             
 *  HighliteItem                [?]             
 *  a(?)                        [IN/OUT]        Void
 *  b(?)                        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
static U8 PhnsetConstSysWallpaperList(U8 **pSysWallpaperStrList, U16 *pSysWallpaperImgIDList, U16 *HighliteItem)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 i, wp_max = 0;
    U16 strID = 0, imgID = 0;
    U8 index_other = 0;
#ifdef __MMI_SWFLASH__
    U8 index_swflash = 0;
#endif
    U8 index_img = 0;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /*
     * SYSTEM WALLPAPER
     */
    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        U8 max_wp_img = MAX_WALLPAPER_IMG - MAX_OTHER_WALLPAPER - MAX_DISPCHAR_SWFLASH;
        U8 max_wp_other = MAX_OTHER_WALLPAPER;
        U8 max_wp_swflash = MAX_DISPCHAR_SWFLASH;

#ifdef __MMI_THEMES_V2_SUPPORT__
        max_wp_other --;                /* when theme screen saver valid delete screen saver image id */         
#endif
        /* Layout
         * 
         *
         * -- Normal Images --
         * -- Normal Images -- SVG
         * -- Normal Images -- M3D
         * -- Analog clock  --
         * -- Digital clock --
         * -- Theme         --
         * -- SWFLASH        --
         * 
         */
         
        /* 
         * Build-in images
         */

        for (i = 0; i < (max_wp_img + max_wp_other + max_wp_swflash); i++)
        {
            if (i < max_wp_img)
            {
                imgID = IMG_ID_PHNSET_WP_START + i;
            }
            else if (max_wp_other &&
                     i >= max_wp_img && 
                     i < (max_wp_img + max_wp_other))
            {
                imgID = IMG_ID_DISPCHAR_OTHER_START + (i - max_wp_img) + 1;
            }
            else if(max_wp_swflash)
            {
                imgID = IMG_ID_DISPCHAR_SWFLASH_START + (i - (max_wp_img + max_wp_other));
            }

            /* normal/SVG/M3D  images*/
            if (imgID >= IMG_ID_PHNSET_WP_START && imgID <= IMG_ID_PHNSET_WP_MAX)
            {
                strID = STR_ID_PHNSET_DISPCHAR_IMGID_START + index_img;
                ++index_img;
            }
            else if ( imgID > IMG_ID_DISPCHAR_OTHER_START && imgID < IMG_ID_DISPCHAR_OTHER_MAX)
            {

            #if !defined(__MMI_UI_TECHNO_IDLESCREEN_BAR__)
            
            #ifdef __MMI_ANALOG_CLOCK__
                /* Analog clock */
                if (imgID == IMG_ID_DISPCHAR_ANALOG_CLK)
                {
                    strID = STR_ID_PHNSET_DISPCHAR_ANALOG;
                }
            #endif /* __MMI_ANALOG_CLOCK__ */ 
            
            #ifdef __MMI_DIGITAL_CLOCK__
                /* Digital clock */
                if (imgID == IMG_ID_DISPCHAR_DIGITAL_CLK)
                {
                    strID = STR_ID_PHNSET_DISPCHAR_DIGITAL;
                }
            #endif /* __MMI_DIGITAL_CLOCK__ */ 
            
            #endif /* !__MMI_UI_TECHNO_IDLESCREEN_BAR__ */ 
            
                if (imgID == IMG_ID_DISPCHAR_THEME_WALLPAPER)
                {
                    strID = STR_ID_DISPCHAR_THEME_WALLPAPER;
                }

                ++index_other;
            }
        #ifdef __MMI_SWFLASH__
            else if (imgID >= IMG_ID_DISPCHAR_SWFLASH_START && imgID <= IMG_ID_DISPCHAR_SWFLASH_MAX)
            {
                    strID = STR_ID_DISPCHAR_SWFLASH_START + index_swflash;
                    ++index_swflash;
            }
        #endif /* __MMI_SWFLASH__*/

            if (pSysWallpaperImgIDList)
            {
                pSysWallpaperImgIDList[i] = imgID;
            }

            if (pSysWallpaperStrList)
            {
                pSysWallpaperStrList[i] = (PU8) GetString(strID);
            }

            if (HighliteItem && g_phnset_cntx_p->curtWpID == pSysWallpaperImgIDList[i])
            {
                *HighliteItem = i;
                g_phnset_cntx_p->curHightlightItem = i;
            }
        }
        wp_max = i;

        MMI_ASSERT(index_other == max_wp_other);
#ifdef __MMI_SWFLASH__        
        MMI_ASSERT(index_swflash == max_wp_swflash);
#endif

    }/* Main Wallpaper */
#ifdef __MMI_SUB_WALLPAPER__
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP)
    {
        for (i = 0; i < MAX_SUB_WALLPAPER_IMG; i++)
        {
            strID = STR_ID_PHNSET_DISPCHAR_IMGID_START + i;

            if (pSysWallpaperImgIDList)
            {
                pSysWallpaperImgIDList[i] = IMG_ID_PHNSET_SUB_WP_START + i;
            }

            if (pSysWallpaperStrList)
            {
                pSysWallpaperStrList[i] = (PU8) GetString(strID);
            }

            if (HighliteItem)
                if (g_phnset_cntx_p->curtSubWpID == pSysWallpaperImgIDList[i])
                {
                    *HighliteItem = i;
                    g_phnset_cntx_p->curHightlightItem = i;
                }

        }
        wp_max = i;
    }
#endif /* __MMI_SUB_WALLPAPER__ */ 
    else
    {
        MMI_ASSERT(0);
    }

    return (wp_max);

}


/*****************************************************************************
 * FUNCTION
 *  EntryPhnsetWallpaperSys
 * DESCRIPTION
 *  This function is to entry function for Setting->Phonesetup->IdleScreenDisplay->Wallpaper (->Fix) ->System
 *  Functionality: Display system wallpaper list
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void EntryPhnsetWallpaperSys(MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    //MMI_ID gid;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_SYSTEM))
	{
	    mmi_popup_display_simple((WCHAR*)GetString(STR_GLOBAL_NOT_AVAILABLE), MMI_EVENT_NOT_AVAILABLE, GRP_ID_ROOT, NULL);
        return;
	}
    if (!parent_gid)
	{
	    parent_gid = GRP_ID_ROOT;
	}
    //gid = mmi_frm_group_get_top_parent_group_id(mmi_frm_group_get_active_id());
    mmi_frm_group_create(
        parent_gid,
        GRP_ID_WALLPAPER_SYSTEM,
        NULL,
        NULL);

    mmi_frm_group_enter(GRP_ID_WALLPAPER_SYSTEM, MMI_FRM_NODE_SMART_CLOSE_FLAG);

    mmi_frm_scrn_first_enter(
        GRP_ID_WALLPAPER_SYSTEM,
        SCR_WALLPAPER_SYSTEM_LIST,
        (FuncPtr)mmi_phnset_entry_wallpaper_sys_int,
        NULL);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_entry_wallpaper_sys_int
 * DESCRIPTION
 *  Internal entry function for wall paper system menu 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_entry_wallpaper_sys_int(mmi_scrn_essential_struct *scrn_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *guiBuffer;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_frm_scrn_enter(
            scrn_data->group_id,
            scrn_data->scrn_id,
            NULL,
            (FuncPtr)mmi_phnset_entry_wallpaper_sys_int,
            MMI_FRM_FULL_SCRN))
    {
        guiBuffer = mmi_frm_scrn_get_gui_buf(scrn_data->group_id, scrn_data->scrn_id);

        RegisterHighlightHandler(PhnsetWallpaperSysHiliteHandler);

        wp_item_amount = PhnsetConstSysWallpaperList(
                            subMenuDataPtrs,
                            g_phnset_cntx_p->SysWPSSList,
                            (U16*) & (g_phnset_cntx_p->curHightlightItem));

        if (g_phnset_cntx_p->curtWpID == 0)
            g_phnset_cntx_p->curHightlightItem = 0;

        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
        
        ShowCategory36Screen(
            STR_GLOBAL_SELECT,
            IMG_SCR_SETTING_CAPTION,
            STR_GLOBAL_VIEW,
            0,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            wp_item_amount,
            subMenuDataPtrs,
            (U16) g_phnset_cntx_p->curHightlightItem,
            guiBuffer);

        SetLeftSoftkeyFunction(EntryPhnsetWallpaperSysView, KEY_EVENT_UP);
        SetCenterSoftkeyFunction(EntryPhnsetWallpaperSysView, KEY_EVENT_UP);

        SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
    }    
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWallpaperSysHiliteHandler
 * DESCRIPTION
 *  This function is Highlight hanlder when scrolling at wallpaper list screen
 *  for Setting->Phonesetup->IdleScreenDisplay->Wallpaper (->Fix) ->System
 * PARAMETERS
 *  nIndex      [IN]            
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallpaperSysHiliteHandler(S32 nIndex)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (nIndex > wp_item_amount - MAX_DISPCHAR_SWFLASH - 1)
        ChangeLeftSoftkey(STR_GLOBAL_PLAY, 0);
    else
        ChangeLeftSoftkey(STR_GLOBAL_VIEW, 0);

    g_phnset_cntx_p->curHightlightItem = (U16) nIndex;
}


/*****************************************************************************
 * FUNCTION
 *  EntryPhnsetWallpaperSysView
 * DESCRIPTION
 *  This function is Entry function to preview wallpaper
 *  for Setting->Phonesetup->IdleScreenDisplay->Wallpaper (->Fix) ->System/Download -> View
 *  Follow functions: PhnsetWallpaperSysViewPre
 *  PhnsetWallpaperSysViewNext
 *  PhnsetWallpaperSet
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void EntryPhnsetWallpaperSysView(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    PU8 wallpaperName;
    U8 *guiBuffer;
    U16 wallpaperId = g_phnset_cntx_p->SysWPSSList[g_phnset_cntx_p->curHightlightItem];
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    g_phnset_cntx_p->isCorrectSet = 0;

    mmi_phnset_enter_switch_screen();

    guiBuffer = mmi_frm_scrn_get_gui_buf(GRP_ID_WALLPAPER_SYSTEM, mmi_frm_scrn_get_active_id());
        
    wallpaperName = (PU8) PhnsetGetWallpaperNameById(wallpaperId);

    wgui_set_touch_title_bar_buttons(); /* enable the display of title bar buttons */

#if defined(__MMI_TOUCH_SCREEN__)
    register_touch_button_handlers(NULL, PhnsetWallpaperSysViewPre, NULL, PhnsetWallpaperSysViewNext);
#endif 
#if !defined(__MMI_UI_TECHNO_IDLESCREEN_BAR__)
#ifdef __MMI_ANALOG_CLOCK__
    /* Category 86 if to View the Analog Clock */
    if ((wallpaperId == IMG_ID_DISPCHAR_ANALOG_CLK))
    {
        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
        ShowCategory86Screen(
            STR_ID_PHNSET_DISPCHAR_ANALOG,
            0,
            STR_GLOBAL_OK,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            IMG_ID_DISPCHAR_ANALOG_CLK,
            guiBuffer);
    }
    else
#endif /* __MMI_ANALOG_CLOCK__ */ 

#ifdef __MMI_DIGITAL_CLOCK__
        /* Category 128 to view Digital Clock */
    if (wallpaperId == IMG_ID_DISPCHAR_DIGITAL_CLK)
    {
        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
        ShowCategory128Screen(
            STR_ID_PHNSET_DISPCHAR_DIGITAL,
            0,
            STR_GLOBAL_OK,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            IMG_ID_DISPCHAR_DIGITAL_CLK,
            guiBuffer);
    }
    else
#endif /* __MMI_DIGITAL_CLOCK__ */ 
#endif /* !__MMI_UI_TECHNO_IDLESCREEN_BAR__ */

    if (wallpaperId == IMG_ID_DISPCHAR_THEME_WALLPAPER)
    {
        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
        ShowCategory130Screen(
            wallpaperName,
            0,
            STR_GLOBAL_OK,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            guiBuffer);
    }
    else
     /* For Normal Viewing */
    {
        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
        wgui_softkey_disable_text_translucence();
        ShowCategory129Screen(
            wallpaperName,
            0,
            STR_GLOBAL_OK,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            wallpaperId,
            guiBuffer);
    }

    SetLeftSoftkeyFunction(PhnsetWallpaperSet, KEY_EVENT_UP);
    SetCenterSoftkeyFunction(PhnsetWallpaperSet, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);

    /* change the key handler for KEY UP event to KEY DOWN event. */
    mmi_frm_send_incomplete_key_event_to_new_screen(MMI_TRUE); /* for handle long press LNK and RNK */    
    SetKeyHandler(PhnsetWallpaperSysViewPre, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
    SetKeyHandler(PhnsetWallpaperSysViewPre, KEY_LEFT_ARROW, KEY_REPEAT);    
    SetKeyHandler(PhnsetWallpaperSysViewPre, KEY_LEFT_ARROW, KEY_LONG_PRESS);        
    SetKeyHandler(PhnsetWallpaperSysViewNext, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
    SetKeyHandler(PhnsetWallpaperSysViewNext, KEY_RIGHT_ARROW, KEY_REPEAT);    
    SetKeyHandler(PhnsetWallpaperSysViewNext, KEY_RIGHT_ARROW, KEY_LONG_PRESS);        
}


/*****************************************************************************
 * FUNCTION
 *  ExitPhnsetWallpaperSysView
 * DESCRIPTION
 *  This function is Exit function for preview wallpaper
 *  for Setting->Phonesetup->IdleScreenDisplay->Wallpaper (->Fix) ->System/Download -> View
 *  Functionality: Add to history
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void ExitPhnsetWallpaperSysView(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->isCorrectSet)
    {
		/*
		DeleteScreenIfPresent(SCR_WALLPAPER_VIEW);
		DeleteScreenIfPresent(SCR_WALLPAPER_SYSTEM_LIST);
        DeleteUptoScrID(g_phnset_cntx_p->ScrAnchor);
        */
        mmi_frm_group_close(GRP_ID_WALLPAPER_SYSTEM);
    }
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWallpaperSysViewPre
 * DESCRIPTION
 *  This function is to view previous wallpaper
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallpaperSysViewPre(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ExitCategoryFunction();
    if (g_phnset_cntx_p->curHightlightItem <= 0)
    {
        if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
        {
            g_phnset_cntx_p->curHightlightItem = wp_item_amount;
        }
    #ifdef __MMI_SUB_WALLPAPER__
        else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP)
        {
            g_phnset_cntx_p->curHightlightItem = MAX_SUB_WALLPAPER_IMG;
        }
    #endif /* __MMI_SUB_WALLPAPER__ */ 
        else
        {
            MMI_ASSERT(MMI_FALSE);
        }
    }

    g_phnset_cntx_p->curHightlightItem--;
    EntryPhnsetWallpaperSysView();
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWallpaperSysViewNext
 * DESCRIPTION
 *  This function is to view next wallpaper
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallpaperSysViewNext(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ExitCategoryFunction();
    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        if (wp_item_amount && (g_phnset_cntx_p->curHightlightItem >= wp_item_amount - 1))
        {
            g_phnset_cntx_p->curHightlightItem = -1;
        }
    }
#ifdef __MMI_SUB_WALLPAPER__
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP)
    {
        if (g_phnset_cntx_p->curHightlightItem >= MAX_SUB_WALLPAPER_IMG - 1)
        {
            g_phnset_cntx_p->curHightlightItem = -1;
        }
    }
#endif /* __MMI_SUB_WALLPAPER__ */ 
    else
    {
        MMI_ASSERT(0);
    }

    g_phnset_cntx_p->curHightlightItem++;
    EntryPhnsetWallpaperSysView();
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWallpaperSet
 * DESCRIPTION
 *  This function is Left softkey handler for set/preview wallpaper
 *  Functionality: Save to nvram, change globol variable gCurrentWallpaper
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallpaperSet(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    PhnsetSetWallpaperByImgID(g_phnset_cntx_p->SysWPSSList[g_phnset_cntx_p->curHightlightItem]);

#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER__
    mmi_phnset_wallpaper_set_vui_live_wallpaper_setting(0); // Turn off Live wallpaper
#endif

    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
    #ifdef __MMI_FILE_MANAGER__
    g_phnset_wallpaper_default_file_1.is_short = 0;
    g_phnset_wallpaper_default_file_2.is_short = 0;    
//        phnset_wpss_default_file_1.isWPShort = 0;
//       phnset_wpss_default_file_2.isWPShort = 0;
        mmi_phnset_del_dirty_file();
    #endif /* __MMI_FILE_MANAGER__ */

    #ifdef __MMI_WALLPAPER_ON_BOTTOM__
        wgui_set_wallpaper_change();    /* 012006 wallpaper Calvin */
    #endif 
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SET_MAIN_WP_ID, g_phnset_cntx_p->curtWpID);
    }
#ifdef __MMI_SUB_WALLPAPER__
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP)
    {
        SUBLCD_UpdateWallpaper();

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SET_SUB_WP_ID, g_phnset_cntx_p->curtSubWpID);
    }
#endif /* __MMI_SUB_WALLPAPER__ */ 
    else
    {
        MMI_ASSERT(0);
    }

    g_phnset_cntx_p->isCorrectSet = 1;

    mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_DONE), MMI_EVENT_SUCCESS, GRP_ID_ROOT, NULL);
#if defined(__MMI_OP11_HOMESCREEN_0301__) || defined(__MMI_OP11_HOMESCREEN_0302__)
    mmi_op11_hs32_set_done_flag();
#endif
    mmi_frm_group_close(GRP_ID_WALLPAPER_SYSTEM);
    if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_MAIN))
	{
        mmi_frm_group_close(GRP_ID_WALLPAPER_MAIN);	
	}
}


/*****************************************************************************
 * FUNCTION
 *  ThemeManagerSetWallpaper
 * DESCRIPTION
 *  ...
 *  * PARAMETERS
 *  a  IN/OUT      void
 *  b  IN       void
 * RETURNS
 *  void
 *****************************************************************************/
void ThemeManagerSetWallpaper(U16 nId)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#ifdef __MMI_FILE_MANAGER__
    S16 error;
#endif

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_cntx_p->curtWpID = nId;
    mmi_dispchar_set_img_id(NVRAM_FUNANDGAMES_SETWALLPAPER, &(g_phnset_cntx_p->curtWpID));

#ifdef __MMI_FILE_MANAGER__
    if (nId == 0)
    {
//        ReadRecord(NVRAM_EF_WPSS_FILENAME_LID, 1, &phnset_wpss_filename, sizeof(phnset_wpss_filename), &error);
        ReadRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 1, &g_phnset_wallpaper_actual_filename, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);        
        g_phnset_cntx_p->isShort = g_phnset_wallpaper_actual_filename.is_short;
        PhnsetSetWallpaperByFileName((S8*) g_phnset_wallpaper_actual_filename.filename);
    }
    else
#endif /* __MMI_FILE_MANAGER__ */
    {
	/* MMI_TRUE for SetIdleScreenWallpaperID means create another layer for wallpaper 
	 * while MMI_FALSE means use current layer
	 */
        SetIdleScreenWallpaperID(nId, MMI_TRUE);
    }

    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SET_THEME_WP_ID, g_phnset_cntx_p->curtWpID);
}


#ifdef __MMI_AVATAR__
/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_avatar_highlight_hdlr
 * DESCRIPTION
 *  This function is Highlight handler for Setting->Phonesetup->IdleScreenDisplay->Wallpaper->3D Avatar
 *  Following Function: mmi_phnset_wallpaper_avatar_entry
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_wallpaper_avatar_highlight_hdlr(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    SetLeftSoftkeyFunction(mmi_phnset_avatar_entry, KEY_EVENT_UP);
    SetCenterSoftkeyFunction(mmi_phnset_avatar_entry, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_avatar_select_path_and_entry_callback_hdlr
 * DESCRIPTION
 *  This function is Highlight handler for Setting->Phonesetup->IdleScreenDisplay->Wallpaper->3D Avatar
 *  Following Function: mmi_phnset_wallpaper_avatar_entry
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 * RETURNS
 *  void
 *****************************************************************************/
extern PS8 PhnsetGetFileNamePointer(PS8 path);
static void mmi_avatar_select_path_and_entry_callback_hdlr(U32 id, U32 serial_num)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 error;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    if (id > 0)
    {
        U32 buffer[2];
        U32 serial_buffer[2];
	    g_phnset_cntx_p->isCorrectSet = 1;

        switch (g_phnset_cntx_p->wpss_type)
        {
            case MMI_PHNSET_TYPE_WP:
            {
                ReadValue(NVRAM_DISPCHAR_AVATAR_WPSS, (U8 *)buffer, DS_DOUBLE, &error);
                ReadValue(NVRAM_DISPCHAR_AVATAR_WPSS_SERIALNUM, (U8 *)serial_buffer, DS_DOUBLE, &error);
                buffer[IMG_ID_DISPCHAR_AVATAR_WALLPAPER - IMG_ID_DISPCHAR_AVATAR_START] = id;
                serial_buffer[IMG_ID_DISPCHAR_AVATAR_WALLPAPER - IMG_ID_DISPCHAR_AVATAR_START] = serial_num;
                WriteValue(NVRAM_DISPCHAR_AVATAR_WPSS, (U8 *)buffer, DS_DOUBLE, &error);
                WriteValue(NVRAM_DISPCHAR_AVATAR_WPSS_SERIALNUM, (U8 *)serial_buffer, DS_DOUBLE, &error);
                PhnsetSetWallpaperByImgID(IMG_ID_DISPCHAR_AVATAR_WALLPAPER);
                
            #ifdef __MMI_WALLPAPER_ON_BOTTOM__
                wgui_set_wallpaper_change();
            #endif /* __MMI_WALLPAPER_ON_BOTTOM__ */

                break;
            }

            case MMI_PHNSET_TYPE_SS:
            {
                g_phnset_cntx_p->curSsID = IMG_ID_DISPCHAR_AVATAR_SCREENSAVER;
                mmi_dispchar_set_img_id(NVRAM_CURRENT_SCREENSVER_ID, &g_phnset_cntx_p->curSsID);
                ReadValue(NVRAM_DISPCHAR_AVATAR_WPSS, (U8 *)buffer, DS_DOUBLE, &error);
                ReadValue(NVRAM_DISPCHAR_AVATAR_WPSS_SERIALNUM, (U8 *)serial_buffer, DS_DOUBLE, &error);
                buffer[IMG_ID_DISPCHAR_AVATAR_SCREENSAVER- IMG_ID_DISPCHAR_AVATAR_START] = id;
                serial_buffer[IMG_ID_DISPCHAR_AVATAR_SCREENSAVER- IMG_ID_DISPCHAR_AVATAR_START] = serial_num;
                WriteValue(NVRAM_DISPCHAR_AVATAR_WPSS, (U8 *)buffer, DS_DOUBLE, &error);
                WriteValue(NVRAM_DISPCHAR_AVATAR_WPSS_SERIALNUM, (U8 *)serial_buffer, DS_DOUBLE, &error);
                break;	
            }

        #ifdef __MMI_POWER_ON_OFF_DISPLAY__
            case MMI_PHNSET_TYPE_PWRON:
            {
                g_phnset_cntx_p->curtPwrOnID = IMG_ID_DISPCHAR_AVATAR_ON;
                mmi_dispchar_set_img_id(NVRAM_CURRENT_POWER_ON_DISPLAY, &g_phnset_cntx_p->curtPwrOnID);
                ReadValue(NARAM_DISPCHAR_AVATAR_ONOFF, (U8 *)buffer, DS_DOUBLE, &error);
                ReadValue(NVRAM_DISPCHAR_AVATAR_ONOFF_SERIALNUM, (U8 *)serial_buffer, DS_DOUBLE, &error);
                buffer[IMG_ID_DISPCHAR_AVATAR_ON - IMG_ID_DISPCHAR_AVATAR_ON] =id;
                serial_buffer[IMG_ID_DISPCHAR_AVATAR_ON - IMG_ID_DISPCHAR_AVATAR_ON] = serial_num;
                WriteValue(NARAM_DISPCHAR_AVATAR_ONOFF, (U8 *)buffer, DS_DOUBLE, &error);
                WriteValue(NVRAM_DISPCHAR_AVATAR_ONOFF_SERIALNUM, (U8 *)serial_buffer, DS_DOUBLE, &error);
                break;			
            }


            case MMI_PHNSET_TYPE_PWROFF:
            {
                g_phnset_cntx_p->curtPwrOffID = IMG_ID_DISPCHAR_AVATAR_OFF;
                mmi_dispchar_set_img_id(NVRAM_CURRENT_POWER_OFF_DISPLAY, &g_phnset_cntx_p->curtPwrOffID);
                ReadValue(NARAM_DISPCHAR_AVATAR_ONOFF, (U8 *)buffer, DS_DOUBLE, &error);
                ReadValue(NVRAM_DISPCHAR_AVATAR_ONOFF_SERIALNUM, (U8 *)serial_buffer, DS_DOUBLE, &error);
                buffer[IMG_ID_DISPCHAR_AVATAR_OFF - IMG_ID_DISPCHAR_AVATAR_ON] = id;
                serial_buffer[IMG_ID_DISPCHAR_AVATAR_OFF - IMG_ID_DISPCHAR_AVATAR_ON] = serial_num;
                WriteValue(NARAM_DISPCHAR_AVATAR_ONOFF, (U8 *)buffer, DS_DOUBLE, &error);
                WriteValue(NVRAM_DISPCHAR_AVATAR_ONOFF_SERIALNUM, (U8 *)serial_buffer, DS_DOUBLE, &error);
                break;
            }
        #endif	/* __MMI_POWER_ON_OFF_DISPLAY__ */


            default:
			    g_phnset_cntx_p->isCorrectSet = 0;

                break;
        }

		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_DONE), MMI_EVENT_SUCCESS, GRP_ID_ROOT, NULL);
    }
    else
    {
        /* DispIdleScrWPBadFilePopup();	*/
    }

    
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_avatar_entry
 * DESCRIPTION
 *  This function is Entry function for Setting->Phonesetup->IdleScreenDisplay->Wallpaper->3D Avatar
 *  Following Function: Show 3D Avatar Menu
 * PARAMETERS           
 *  a(?)            [IN/OUT]        Void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_avatar_entry(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

	switch(g_phnset_cntx_p->wpss_type)
	{
		case MMI_PHNSET_TYPE_WP:	/* if 3d avatar use for wallpaper */
			mmi_avatar_select_path_and_enter(MMI_AVATAR_APP_WALLPAPER, 
                GetRootTitleIcon(MENU_SETTING_WALLPAPER), mmi_avatar_select_path_and_entry_callback_hdlr);
			break;

		case MMI_PHNSET_TYPE_SS:	/* 3d avatar for screen saver */
			mmi_avatar_select_path_and_enter(MMI_AVATAR_APP_SCREENSAVER, 
                GetRootTitleIcon(MENU_SETTING_WALLPAPER), mmi_avatar_select_path_and_entry_callback_hdlr);
			break;

#ifdef __MMI_POWER_ON_OFF_DISPLAY__
		case MMI_PHNSET_TYPE_PWRON:
			mmi_avatar_select_path_and_enter(MMI_AVATAR_APP_POWERON_ANIMATION, 
                GetRootTitleIcon(MENU_SETTING_WALLPAPER), mmi_avatar_select_path_and_entry_callback_hdlr);
			break;

		case MMI_PHNSET_TYPE_PWROFF:
			mmi_avatar_select_path_and_enter(MMI_AVATAR_APP_POWEROFF_ANIMATION, 
                GetRootTitleIcon(MENU_SETTING_WALLPAPER), mmi_avatar_select_path_and_entry_callback_hdlr);
			break;
#endif

		default:
			break;
	}
		
}
#endif /* __MMI_AVATAR__ */


#ifdef __MMI_FILE_MANAGER__


/*****************************************************************************
 * FUNCTION
 *  PhnsetWallpaperForwardFromFmgr
 * DESCRIPTION
 *  This function is call back function for file manager
 *  Following Function:
 * PARAMETERS
 *  path            [?]             
 *  is_short        [IN]            
 *  a(?)            [IN/OUT]        Void
 *  b(?)            [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallpaperForwardFromFmgr(void *path, filetypes_file_type_enum type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_event_struct evt;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_WP_FWFROM_FMGR, path, 1);
#if 0    
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef JPG_DECODE        
/* under construction !*/
/* under construction !*/
#endif /* JPG_DECODE */ 
#if defined(GDI_USING_PNG)
/* under construction !*/
#endif  
#ifdef M3D_MMI_SUPPORT
/* under construction !*/
#endif  
#if defined(SVG_SUPPORT) && !defined(__MMI_VUI_ENGINE__)        
/* under construction !*/
#endif
#if defined(__DRM_V02__)
/* under construction !*/
#endif       
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
    if (!mmi_phnset_display_check_file_type(type, MMI_PHNSET_TYPE_WP))
	{
		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_UNSUPPORTED_FORMAT), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
        return;	    
	}
    if (path)
    {
        /* Prevent memory leck, after buffer is free, set pointer to NULL */
        if (phnset_dispchar_strp)
		{
			mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_NOT_AVAILABLE), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
			return;
		}

        g_phnset_cntx_p->isShort = (S32) 1;

        phnset_dispchar_strp = OslMalloc((SRV_FMGR_PATH_MAX_LEN + 1) * 2);
        if (phnset_dispchar_strp)
        {
            mmi_ucs2cpy((S8*) phnset_dispchar_strp, (S8*) path);
        }
        else
        {
            /* GoBackToHistory(SCR_IDLE_SCR_DISP); No this screen now */
            // TODO: Modify to the correct behavior
            return;
        }

        /* file limitation check - limitation is define in file manager util */
        if (!mmi_fmgr_util_file_limit_check(FMGR_LIMIT_WALLPAPER, (PS8) phnset_dispchar_strp, &error_str_ptr))
        {
            DispIdleScrWPBadFilePopup();
            PhnsetWpUsrDefFreeBuf();
            return;
        }

        g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP;
        g_phnset_cntx_p->ScrAnchor = GetCurrScrnId();
        /* Use post event handler the preview screen to avoid stack overflow Cong Zhou 10/06/01*/
        MMI_FRM_INIT_EVENT(&evt, 0);
        mmi_frm_post_event(&evt, mmi_phnset_wallpaper_entry_forward_from_fmgr, NULL);
    }
    else
    {
		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_ERROR), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_entry_forward_from_fmgr
 * DESCRIPTION
 *  Turn the process in to async to avoid stack overflow
 *  Following Function:
 * PARAMETERS
 *
 * RETURNS
 *  MMI_RET_OK
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_entry_forward_from_fmgr(mmi_event_struct *param)
{
	PhnsetWpUsrDefPreView(GRP_ID_ROOT);
	return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetSubWallpaperForwardFromFmgr
 * DESCRIPTION
 *  This function is call back function for file manager
 *  Following Function:
 * PARAMETERS
 *  path            [?]             
 *  is_short        [IN]            
 *  a(?)            [IN/OUT]        Void
 *  b(?)            [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
#ifdef __MMI_SUB_WALLPAPER__

void PhnsetSubWallpaperForwardFromFmgr(void *path, filetypes_file_type_enum type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SUB_WP_FWFROM_FMGR, path, 1);
#if 0    
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef JPG_DECODE        
/* under construction !*/
/* under construction !*/
#endif /* JPG_DECODE */ 
#if defined(GDI_USING_PNG)
/* under construction !*/
#endif  
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef JPG_DECODE
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* JPG_DECODE */
#endif

    if (!mmi_phnset_display_check_file_type(type, MMI_PHNSET_TYPE_SUB_WP))
	{
		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_UNSUPPORTED_FORMAT), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
        return;	    
	}

    g_phnset_cntx_p->isShort = (S32) 1;

    if (path)
    {
        /* Prevent memory leck, after buffer is free, set pointer to NULL */
        ASSERT(phnset_dispchar_strp == NULL);

        phnset_dispchar_strp = OslMalloc((SRV_FMGR_PATH_MAX_LEN + 1) * 2);
        if (phnset_dispchar_strp)
        {
            mmi_ucs2cpy((S8*) phnset_dispchar_strp, (S8*) path);
        }
        else
        {
            /* GoBackToHistory(SCR_IDLE_SCR_DISP); No this screen now */
            // TODO: Modify to the correct behavior
            return;
        }

        /* file limitation check - limitation is define in file manager util */
        if (!mmi_fmgr_util_file_limit_check(FMGR_LIMIT_SUB_WALLPAPER, (PS8) phnset_dispchar_strp, &error_str_ptr))
        {
            DispIdleScrWPBadFilePopup();
            PhnsetWpUsrDefFreeBuf();
            return;
        }

        g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_SUB_WP;
        g_phnset_cntx_p->ScrAnchor = GetCurrScrnId();

        PhnsetWpUsrDefPreView(GRP_ID_ROOT);
    }
    else
    {
		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_ERROR), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
    }
}

#endif /* __MMI_SUB_WALLPAPER__ */ 


/*****************************************************************************
 * FUNCTION
 *  PhnsetWpUsrDefFreeBuf
 * DESCRIPTION
 *  This function is to free file name string buffer
 *  Following Function:
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWpUsrDefFreeBuf(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (phnset_dispchar_strp)
    {
        OslMfree(phnset_dispchar_strp);
        phnset_dispchar_strp = NULL;
    }
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWpUsrDefSelect
 * DESCRIPTION
 *  This function is LSK handler for set user defined wallpaper/screen saver
 *  Following Function:
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWpUsrDefSelect(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        
        PhnsetSetWallpaperByFileName((S8*) phnset_dispchar_strp);
    #ifdef __MMI_WALLPAPER_ON_BOTTOM__
        wgui_set_wallpaper_change();
    #endif 
		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_DONE), MMI_EVENT_SUCCESS, GRP_ID_ROOT, NULL);

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_WP_USER_DEF_SELECT, phnset_dispchar_strp);

    }
#ifdef __MMI_SUB_WALLPAPER__
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP)
    {
        PhnsetSetWallpaperByFileName((S8*) phnset_dispchar_strp);
		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_DONE), MMI_EVENT_SUCCESS, GRP_ID_ROOT, NULL);

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SUBWP_USER_DEF_SELECT, phnset_dispchar_strp);
    }
#endif /* __MMI_SUB_WALLPAPER__ */ 
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
    {
        PhnsetSetScrSvrByFileName((S8*) phnset_dispchar_strp);
		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_DONE), MMI_EVENT_SUCCESS, GRP_ID_ROOT, NULL);

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHSNET_SS_USER_DEF_SELECT, phnset_dispchar_strp);

    }
    else
    {
        ASSERT(0);
    }
    if (mmi_frm_group_is_present(GRP_ID_DISPLAY_FMGR_COMMON))
	{
        mmi_frm_group_close(GRP_ID_DISPLAY_FMGR_COMMON);	
	}
    else
    {
        mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW);
    }
    /* DeleteScreenIfPresent(SCR_IDLE_SCR_DISP_WP_PREVIEW); */
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWpUsrDefPreViewScrDelCB
 * DESCRIPTION
 *  This function is RSK handler for set user define wallpaper/screensaver
 *  Following Function:
 * PARAMETERS
 *  ptr         [?]             
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
U8 PhnsetWpUsrDefPreViewScrDelCB(void *ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    PhnsetWpUsrDefFreeBuf();

    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWpUsrDefGoBack
 * DESCRIPTION
 *  This function is RSK handler for set user define wallpaper/screensaver
 *  Following Function:
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWpUsrDefGoBack(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    PhnsetWpUsrDefFreeBuf();

    GoBackHistory();
}


/*****************************************************************************
 * FUNCTION
 *  ExitPhnsetWpUsrDefPreView
 * DESCRIPTION
 *  Exit handler of PhnsetWpUsrDefPreView
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void ExitPhnsetWpUsrDefPreView(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->isCorrectSet)
    {
        PhnsetWpUsrDefFreeBuf();
        /* mmi_frm_scrn_close_active_id(); */
        /*
        DeleteUptoScrID(g_phnset_cntx_p->ScrAnchor);
        */
        /* mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW); */
    }
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWpUsrDefPreView
 * DESCRIPTION
 *  This function is to preview user define wallpaper/screensaver
 *  Following Function:
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWpUsrDefPreView(MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!parent_gid)
	{
	    parent_gid = GRP_ID_ROOT;
	}
    if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_PREVIEW))
	{
	    mmi_popup_display_simple((WCHAR*)GetString(STR_GLOBAL_NOT_AVAILABLE), MMI_EVENT_NOT_AVAILABLE, GRP_ID_ROOT, NULL);
        return;
	}

    mmi_frm_group_create(parent_gid, GRP_ID_WALLPAPER_PREVIEW, mmi_phnset_wallpaper_preview_proc, NULL);
    mmi_frm_group_enter(GRP_ID_WALLPAPER_PREVIEW, MMI_FRM_NODE_SMART_CLOSE_FLAG);                    	

    mmi_frm_scrn_first_enter(
        GRP_ID_WALLPAPER_PREVIEW,
        SCR_IDLE_SCR_DISP_WP_PREVIEW,
        (FuncPtr)mmi_phnset_entry_wpss_common_userdef_preview,
        NULL);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_entry_wpss_common_userdef_preview
 * DESCRIPTION
 *  Internal entry function of WallPaper, Screen Saver and Power on off Display user defined resource preview screen 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_entry_wpss_common_userdef_preview(mmi_scrn_essential_struct *scrn_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
     U8 *gui_buffer;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if(!mmi_frm_scrn_enter(
        scrn_data->group_id,
        scrn_data->scrn_id,
        NULL,
        (FuncPtr)mmi_phnset_entry_wpss_common_userdef_preview,
        MMI_FRM_FULL_SCRN) 
        || phnset_dispchar_strp == NULL)
    {
        return;
    }
    gui_buffer = mmi_frm_scrn_get_gui_buf(scrn_data->group_id, scrn_data->scrn_id);

    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_WP_USER_DEF_VIEW, phnset_dispchar_strp);

    CallbackWpSsLSK = PhnsetWpUsrDefSelect;
    g_phnset_cntx_p->isCorrectSet = 0;
#if defined(__MMI_SCREENSAVER_DISPLAY_VIDEO__) && defined(__MTK_TARGET__)
    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS
        && srv_fmgr_types_find_group_by_filename_str((WCHAR*)phnset_dispchar_strp) == FMGR_GROUP_VIDEO)
    {
    #ifdef __DRM_SUPPORT__
        wgui_catvdo_set_drm_flag(WGUI_CATVDO_DRM_DISABLE_CONSUME_ALL);
    #endif /* __DRM_SUPPORT__ */

        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
        ShowCategory225Screen(
            STR_GLOBAL_VIEW,            /* title_str */
            IMG_SCR_SETTING_CAPTION,    /* title_icon */
            STR_GLOBAL_OK,              /* lsk_str */
            IMG_GLOBAL_OK,              /* lsk_icon */
            STR_GLOBAL_BACK,            /* rsk_str */
            IMG_GLOBAL_BACK,            /* rsk_icon */
            0,                          /* video_id */
            (S8*) phnset_dispchar_strp, /* video_filename */
            1,                          /* repeat_count */
            TRUE,                       /* is_visual_update */
            FALSE,                      /* is_play_audio */
            TRUE,                       /* is_lcd_no_sleep */
            GDI_COLOR_WHITE,            /* bg_color */
            mmi_phnset_wallpaper_video_play_callback,
            gui_buffer);
    }
    else
#endif /* defined(__MMI_SCREENSAVER_DISPLAY_VIDEO__) && defined(__MTK_TARGET__) */ 
    {
			wgui_cat222_disable_err_msg_display();
            EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
			ShowCategory222Screen(
				STR_GLOBAL_VIEW,
				IMG_SCR_SETTING_CAPTION,
				STR_GLOBAL_OK,
				IMG_GLOBAL_OK,
				STR_GLOBAL_BACK,
				IMG_GLOBAL_BACK,
				GDI_COLOR_WHITE,
				NULL,
				(S8*) phnset_dispchar_strp,
				FALSE,
			mmi_phnset_wallpaper_image_play_callback,
				GDI_IMAGE_SRC_FROM_FILE);
    }

    SetRightSoftkeyFunction(PhnsetWpUsrDefGoBack, KEY_EVENT_UP);

    if ((g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP) || (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS))
    {
        SetLeftSoftkeyFunction(mmi_phnset_copy_wpss_check_device, KEY_EVENT_UP);      
        SetCenterSoftkeyFunction(mmi_phnset_copy_wpss_check_device, KEY_EVENT_UP);      
    }
    else
    {
        SetLeftSoftkeyFunction(CallbackWpSsLSK, KEY_EVENT_UP);
        SetCenterSoftkeyFunction(CallbackWpSsLSK, KEY_EVENT_UP);        
    }    
}

 
/*****************************************************************************
 * FUNCTION
 *  PhnsetWallpaperSelectFmgrCallBack
 * DESCRIPTION
 *  This function is call back function for IdleScreenDisplay->Wallpaper->User Define
 *  Following Function:
 * PARAMETERS
 *  path            [?]             
 *  is_short        [IN]            
 *  a(?)            [IN/OUT]        Void
 *  b(?)            [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallpaperSelectFmgrCallBack(void *path, int is_short)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (path)
    {
        if(mmi_phnset_check_file_limit(path) != PHNSET_WP_SS_SET_NO_ERROR)
        {
            DispIdleScrWPBadFilePopup();
            PhnsetWpUsrDefFreeBuf();
            return;
        }

        if(mmi_phnset_wallpaper_init_filename(path, is_short) != PHNSET_WP_SS_SET_NO_ERROR)
        {
            EntryIdleScreen();
            return;
        }

#ifdef __DRM_SUPPORT__        
        if(mmi_phnset_wallpaper_drm_check()!= PHNSET_WP_SS_SET_NO_ERROR)
        {
                DispIdleScrWPBadFilePopup();
                return;
        }
#endif /* __DRM_SUPPORT__ */

        PhnsetWpUsrDefPreView(GRP_ID_DISPLAY_FMGR_COMMON);

    }
    else
    {
		mmi_frm_group_close(mmi_frm_group_get_active_id());
    }
}


/*****************************************************************************
 * FUNCTION
 *  EntryPhnsetWallpaperFmgr
 * DESCRIPTION
 *  This function is Entry function for Setting->Phonesetup->IdleScreenDisplay->Wallpaper (->Fix) -> User Define
 *  Follow functions:
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void EntryPhnsetWallpaperFmgr(MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#if defined(__MMI_FILE_MANAGER__)
    FMGR_FILTER filter;
    U8 option = 1;
    MMI_ID fmgrcui_id;
#endif    

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

#if defined(__MMI_FILE_MANAGER__) 
    if (mmi_frm_group_is_present(GRP_ID_DISPLAY_FMGR_COMMON))
	{
	    mmi_popup_display_simple((WCHAR*)GetString(STR_GLOBAL_NOT_AVAILABLE), MMI_EVENT_NOT_AVAILABLE, GRP_ID_ROOT, NULL);
        return;
	}
    if (!parent_gid)
	{
	    parent_gid = GRP_ID_ROOT;
	}
    
    mmi_frm_group_create(
        parent_gid,
        GRP_ID_DISPLAY_FMGR_COMMON,
        mmi_phnset_display_fmgr_common_proc,
        NULL);
    mmi_frm_group_enter(GRP_ID_DISPLAY_FMGR_COMMON, MMI_FRM_NODE_SMART_CLOSE_FLAG);
    
    FMGR_FILTER_INIT(&filter);
    mmi_phnset_display_set_file_filter(&filter, g_phnset_cntx_p->wpss_type);

    FMGR_FILTER_SET(&filter, FMGR_TYPE_FOLDER);
    FMGR_FILTER_SET(&filter, FMGR_TYPE_FOLDER_DOT);

        fmgrcui_id = cui_file_selector_create(
            GRP_ID_DISPLAY_FMGR_COMMON,
            L"root",
            &filter,
            CUI_FILE_SELECTOR_STYLE_FILE_ONLY,
            CUI_FILE_SELECTOR_OPT_FOLDER_TRAVERSE_ALL | CUI_FILE_SELECTOR_OPT_FIXED_PATH_ON);

        cui_file_selector_run(fmgrcui_id);

#endif /* defined(__MMI_FILE_MANAGER__) */ 

}


/*****************************************************************************
 * FUNCTION
 *  mmi_fmgr_phnset_notify_hdlr
 * DESCRIPTION
 *  callback function of memory card plug out
 * PARAMETERS
 *  void
 * RETURNS
 *  BOOL
 *****************************************************************************/
BOOL mmi_fmgr_phnset_notify_hdlr(U32 notify_flag, void* para)
{
}


/*****************************************************************************
 * FUNCTION
 *  mmi_fmgr_wp_ss_pwr_notify_hdlr
 * DESCRIPTION
 *  FMGR notification handler for wallpaper, screensaver and power on off display 
 * PARAMETERS
 *  
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
mmi_ret mmi_fmgr_wp_ss_pwr_notify_hdlr(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 temp;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_001);

#ifdef __MMI_FILE_MANAGER__
    switch(param->evt_id)
    {
    case EVT_ID_SRV_FMGR_NOTIFICATION_DEV_PLUG_OUT:
        /* no file in preview */
        if (phnset_dispchar_strp == NULL)
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_002);
            return MMI_RET_OK;
        }

        temp = FS_GetDevStatus((U8)phnset_dispchar_strp[0], FS_MOUNT_STATE_ENUM);
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_003, temp);

        temp = FS_GetDevStatus(FS_DEVICE_TYPE_CARD, FS_MOUNT_STATE_ENUM);
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_004, temp);

        /* verify device status of preview file is OK */
        /* when preview a file in flash and plug out memory card, return directly */
        if (FS_GetDevStatus((U8)phnset_dispchar_strp[0], FS_MOUNT_STATE_ENUM) == FS_NO_ERROR)
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_005);
            return MMI_RET_OK;
        }

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_006, g_phnset_cntx_p->wpss_type);

        switch(g_phnset_cntx_p->wpss_type)
        {
        case MMI_PHNSET_TYPE_WP:
            {
                /* preview screen exist and storage error && only entry from phone setup */
                MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_007);

                if (mmi_frm_scrn_is_present(GRP_ID_WALLPAPER_PREVIEW, SCR_IDLE_SCR_DISP_WP_PREVIEW, MMI_FRM_NODE_ALL_FLAG))
                {
                    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_008);
                    mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW);
                    /* DeleteScreenIfPresent(SCR_IDLE_SCR_DISP_WP_PREVIEW); */
                    g_phnset_cntx_p->storage_invalid = MMI_TRUE;
                }

            }
        	break;

#ifdef __MMI_SUB_WALLPAPER__
        case MMI_PHNSET_TYPE_SUB_WP:
            {
                /* preview screen exist and storage error */
                MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_007);
                if (mmi_frm_scrn_is_present(GRP_ID_WALLPAPER_PREVIEW, SCR_IDLE_SCR_DISP_WP_PREVIEW, MMI_FRM_NODE_ALL_FLAG))
                {
                    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_008);
                    mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW);
                    /* DeleteScreenIfPresent(SCR_IDLE_SCR_DISP_WP_PREVIEW); */
                    g_phnset_cntx_p->storage_invalid = MMI_TRUE;
                }

            }
            break;
#endif /* __MMI_SUB_WALLPAPER__ */        

        case MMI_PHNSET_TYPE_SS:
            {
                /* preview screen exist and storage error */
                MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_009);

                if (mmi_frm_scrn_is_present(GRP_ID_WALLPAPER_PREVIEW, SCR_IDLE_SCR_DISP_WP_PREVIEW, MMI_FRM_NODE_ALL_FLAG))
                {
                    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_008);
                    mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW);
                    /* DeleteScreenIfPresent(SCR_IDLE_SCR_DISP_WP_PREVIEW); */
                    g_phnset_cntx_p->storage_invalid = MMI_TRUE;
                }

            }
            break;
            
#ifdef __MMI_POWER_ON_OFF_DISPLAY__
        case MMI_PHNSET_TYPE_PWRON:
            {
                /* preview screen exist and storage error */
                MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_010);
                if (mmi_frm_scrn_is_present(GRP_ID_POWER_ON_OFF_PREVIEW, SCR_ID_PHNSET_POWER_ON_USER_VIEW, MMI_FRM_NODE_ALL_FLAG))
                {
                    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_008);
                    mmi_frm_group_close(GRP_ID_POWER_ON_OFF_PREVIEW);
                    /* DeleteScreenIfPresent(SCR_IDLE_SCR_DISP_WP_PREVIEW); */
                    g_phnset_cntx_p->storage_invalid = MMI_TRUE;
                }                
                
            }
            break;

        case MMI_PHNSET_TYPE_PWROFF:
            {
                /* preview screen exist and storage error */
                MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_011);
                if (mmi_frm_scrn_is_present(GRP_ID_POWER_ON_OFF_PREVIEW, SCR_ID_PHNSET_POWER_OFF_USER_VIEW, MMI_FRM_NODE_ALL_FLAG))
                {
                    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_008);
                    mmi_frm_group_close(GRP_ID_POWER_ON_OFF_PREVIEW);
                    /* DeleteScreenIfPresent(SCR_IDLE_SCR_DISP_WP_PREVIEW); */
                    g_phnset_cntx_p->storage_invalid = MMI_TRUE;
                }                 
                
            }
            break;
#endif /* __MMI_POWER_ON_OFF_DISPLAY__ */

        default:
            break;
        }


        break;
    }

#endif /* __MMI_FILE_MANAGER__ */

    return MMI_RET_OK;
    
}


#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef __MMI_SUB_WALLPAPER__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* __MMI_SUB_WALLPAPER__ */        
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef __MMI_POWER_ON_OFF_DISPLAY__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* __MMI_POWER_ON_OFF_DISPLAY__ */
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* 0 */

#endif /* __MMI_FILE_MANAGER__ */ 


/*****************************************************************************
 * FUNCTION
 *  DispIdleScrWPBadFilePopup
 * DESCRIPTION
 *  This function is call back function for showcategories33screen,
 *  If display user defined image got problem in idle screen, this function will be executed
 *  Follow functions:
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
static void DispIdleScrWPBadFilePopup(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (error_str_ptr)
    {
		mmi_popup_display_simple((WCHAR*) error_str_ptr, MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
    }
    else
    {
		mmi_popup_display_simple((WCHAR*) GetString(STR_IDLE_WP_DECODE_ERR), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
    }
    error_str_ptr = NULL;

}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWallpaperBadFileCallBack
 * DESCRIPTION
 *  This function is call back function for showcategories33screen,
 *  If display user defined image got problem in idle screen, this function will be executed
 *  Follow functions:
 * PARAMETERS
 *  imgID       [IN]            
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            Void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallpaperBadFileCallBack(U16 strID)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (strID)
        error_str_ptr = (PS8)GetString(strID);
    else
        error_str_ptr = NULL;
    
    StartTimer(IDLE_SHOW_BADFILE_WARNING_TIMER, 100, PhnsetRstWallpaperDefault);

    /* g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP; */
}


#ifdef __MMI_SUB_WALLPAPER__
/*****************************************************************************
 * FUNCTION
 *  PhnsetWallpaperSubBadFileCallBack
 * DESCRIPTION
 *  
 * PARAMETERS
 *  imgID       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWallpaperSubBadFileCallBack(U16 imgID)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    error_str_ptr = NULL;
    StartTimer(IDLE_SHOW_SUB_BADFILE_WARNING_TIMER, 1000, PhnsetRstSubWallpaperDefault);

    /* g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_SUB_WP; */

}

#endif /* __MMI_SUB_WALLPAPER__ */ 


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetDisplayType
 * DESCRIPTION
 *  
 * PARAMETERS
 *  id      [IN]        
 * RETURNS
 *  
 *****************************************************************************/
PHNSET_TYPE_DISP PhnsetGetDisplayType(U16 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((id >= IMG_ID_PHNSET_WP_START && id <= IMG_ID_PHNSET_WP_MAX)
#ifdef __MMI_SUB_WALLPAPER__
        || (id >= IMG_ID_PHNSET_SUB_WP_START && id <= IMG_ID_PHNSET_SUB_WP_MAX)
#endif 
        || (id >= IMG_ID_PHNSET_SS_START && id <= IMG_ID_PHNSET_SS_MAX)
#if !defined(__MMI_UI_TECHNO_IDLESCREEN_BAR__)
#ifdef __MMI_ANALOG_CLOCK__
        || (id == IMG_ID_DISPCHAR_ANALOG_CLK)
#endif 
#ifdef __MMI_DIGITAL_CLOCK__
        || (id == IMG_ID_DISPCHAR_DIGITAL_CLK)
#endif 
#endif /* !__MMI_UI_TECHNO_IDLESCREEN_BAR__ */
        || (id == IMG_ID_DISPCHAR_THEME_WALLPAPER)
#ifdef __MMI_THEMES_V2_SUPPORT__
        || (id == IMG_ID_DISPCHAR_THEME_SCREENSAVER)
#endif 
#ifdef __MMI_POWER_ON_OFF_DISPLAY__
        || (id >= IMG_ID_PHNSET_ON_START && id <= IMG_ID_PHNSET_ON_MAX)
        || (id >= IMG_ID_PHNSET_OFF_START && id <= IMG_ID_PHNSET_OFF_MAX)
#else /* __MMI_POWER_ON_OFF_DISPLAY__ */ 
        || (id == IMG_ID_PHNSET_ON_ANIMATION_DEFAULT) || (id == IMG_ID_PHNSET_OFF_ANIMATION_DEFAULT)
#endif /* __MMI_POWER_ON_OFF_DISPLAY__ */ 
        )
    {
        return PHNSET_TYPE_DISP_IMAGE;
    }
#ifdef __MMI_SWFLASH__
    else if (id >= IMG_ID_DISPCHAR_SWFLASH_START && id <= IMG_ID_DISPCHAR_SWFLASH_MAX)
    {
        return PHNSET_TYPE_DISP_SWFLASH;
    }
#endif
#if defined(__MMI_VIDEO_PLAY_SUPPORT__) && defined(__MTK_TARGET__)
    else if ((id >= IMG_ID_PHNSET_SS_VDO_START && id <= IMG_ID_PHNSET_SS_VDO_MAX)
#ifdef __MMI_POWER_ON_OFF_DISPLAY__
             || (id >= IMG_ID_PHNSET_ON_VDO_START && id <= IMG_ID_PHNSET_ON_VDO_MAX)
             || (id >= IMG_ID_PHNSET_OFF_VDO_START && id <= IMG_ID_PHNSET_OFF_VDO_MAX)
#endif /* __MMI_POWER_ON_OFF_DISPLAY__ */ 
        )
        return PHNSET_TYPE_DISP_VIDEO;
#endif /* defined(__MMI_VIDEO_PLAY_SUPPORT__) && defined(__MTK_TARGET__) */ 
#ifdef __MMI_AVATAR__
else if (id >= IMG_ID_DISPCHAR_AVATAR_START&&
         id <= IMG_ID_DISPCHAR_AVATAR_END)
{
    return PHNSET_TYPE_DISP_AVATAR;
}
#endif
    else if (id == 0x00)
    {
        return PHNSET_TYPE_DISP_USER;
    }
    else
    {
        return PHNSET_TYPE_DISP_INVALID;
    }
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetWpSsPlayCallBack
 * DESCRIPTION
 *  
 * PARAMETERS
 *  result      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWpSsPlayCallBack(S32 result, MMI_BOOL is_video)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_WPSS_PLAY_CALLBACK, result);

    if (result >= 0)
    {
        return;
    }
    else
    {
        mmi_event_notify_enum error_popup_type;
        MMI_ID_TYPE popup_string_id;
        if (is_video)
    	{
            popup_string_id = mdi_util_get_mdi_error_info(result, &error_popup_type);            	
    }
    else
    {
            error_popup_type = MMI_EVENT_FAILURE;
            popup_string_id = STR_GLOBAL_UNSUPPORTED_FORMAT;
        }

        mmi_popup_display_simple((WCHAR*)GetString(popup_string_id), error_popup_type, GRP_ID_ROOT, NULL);

        if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP 
#ifdef __MMI_SUB_WALLPAPER__            
            || g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP
#endif
            || g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
    	{
            /* Close wallpaper / screen saver preview screen */            
            if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_PREVIEW))
    	{
    	    mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW);
    	}
            /* Close wallpaper system view screen */
            if (mmi_frm_scrn_is_present(GRP_ID_WALLPAPER_SYSTEM, SCR_WALLPAPER_VIEW, MMI_FRM_NODE_ALL_FLAG))
        	{
                mmi_frm_scrn_close(GRP_ID_WALLPAPER_SYSTEM, SCR_WALLPAPER_VIEW);
        	}            
            if (mmi_frm_scrn_is_present(GRP_ID_WALLPAPER_SYSTEM, SCR_WALLPAPER_VIEW_2, MMI_FRM_NODE_ALL_FLAG))
        	{
                mmi_frm_scrn_close(GRP_ID_WALLPAPER_SYSTEM, SCR_WALLPAPER_VIEW_2);
        	}                        
            /* Close screen saver system view screen */
            if (mmi_frm_scrn_is_present(GRP_ID_SCREENSAVER_SYSTEM, SCR_SCREENSAVER_VIEW, MMI_FRM_NODE_ALL_FLAG))
        	{
                mmi_frm_scrn_close(GRP_ID_SCREENSAVER_SYSTEM, SCR_SCREENSAVER_VIEW);
        	}            
            if (mmi_frm_scrn_is_present(GRP_ID_SCREENSAVER_SYSTEM, SCR_SCREENSAVER_VIEW_2, MMI_FRM_NODE_ALL_FLAG))
        	{
                mmi_frm_scrn_close(GRP_ID_SCREENSAVER_SYSTEM, SCR_SCREENSAVER_VIEW_2);
        	}                                    
    	}
#ifdef __MMI_POWER_ON_OFF_DISPLAY__
        if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_PWROFF
            || g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_PWRON)
    	{
            /* Close power on/off display preview screen */            
            if (mmi_frm_group_is_present(GRP_ID_POWER_ON_OFF_PREVIEW))
    	{
    	    mmi_frm_group_close(GRP_ID_POWER_ON_OFF_PREVIEW);
    	}
            /* Close power on/off display system view screen */
            if (mmi_frm_scrn_is_present(GRP_ID_POWER_ON_OFF_SYSTEM, SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW, MMI_FRM_NODE_ALL_FLAG))
        	{
                mmi_frm_scrn_close(GRP_ID_POWER_ON_OFF_SYSTEM, SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW);
        	}            
            if (mmi_frm_scrn_is_present(GRP_ID_POWER_ON_OFF_SYSTEM, SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW_2, MMI_FRM_NODE_ALL_FLAG))
        	{
                mmi_frm_scrn_close(GRP_ID_POWER_ON_OFF_SYSTEM, SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW_2);
        	}   
            if (mmi_frm_scrn_is_present(GRP_ID_POWER_ON_OFF_SYSTEM, SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW, MMI_FRM_NODE_ALL_FLAG))
        	{
                mmi_frm_scrn_close(GRP_ID_POWER_ON_OFF_SYSTEM, SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW);
        	}            
            if (mmi_frm_scrn_is_present(GRP_ID_POWER_ON_OFF_SYSTEM, SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW_2, MMI_FRM_NODE_ALL_FLAG))
        	{
                mmi_frm_scrn_close(GRP_ID_POWER_ON_OFF_SYSTEM, SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW_2);
        	}               
    	}
#endif        
        DisableLeftSoftkey(STR_GLOBAL_OK, NULL);
        DisableRightSoftkey(STR_GLOBAL_BACK, NULL);
    #ifdef __MMI_FILE_MANAGER__
        PhnsetWpUsrDefFreeBuf();
    #endif /* __MMI_FILE_MANAGER__ */
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_image_play_callback
 * DESCRIPTION
 *  Play callback for image display 
 * PARAMETERS
 *  result    :    [IN] GDI error code
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_wallpaper_image_play_callback(S32 result)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    PhnsetWpSsPlayCallBack(result, MMI_FALSE);
    }

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_video_play_callback
 * DESCRIPTION
 *  Video play callback function for wallpaper and screen saver 
 * PARAMETERS
 *  result    : [IN]    MDI error code
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_wallpaper_video_play_callback(S32 result)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    PhnsetWpSsPlayCallBack(result, MMI_TRUE);    
}


/* 
 * Externel Interfaces
 */


/*****************************************************************************
 * FUNCTION
 *  PhnsetRstWallpaperDefault
 * DESCRIPTION
 *  This function is to set wallpaper to default one
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            ImageId
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetRstWallpaperDefault(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_cntx_p->curtWpID = RstGetWallpaperImgIdDefault();

    if (!srv_bootup_is_booting() 
#if defined(SYNCML_DM_SUPPORT) && defined(__DM_LAWMO_SUPPORT__)        
        && !mmi_dmui_is_phone_lock()
#endif
        )
    {
        DispIdleScrWPBadFilePopup();
    }

    mmi_dispchar_set_img_id(NVRAM_FUNANDGAMES_SETWALLPAPER, &(g_phnset_cntx_p->curtWpID));
    SetIdleScreenWallpaperID(g_phnset_cntx_p->curtWpID, MMI_TRUE);

    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_RST_WP_DEFAULT, g_phnset_cntx_p->curtWpID);

}

#ifdef __MMI_SUB_WALLPAPER__


/*****************************************************************************
 * FUNCTION
 *  PhnsetRstSubWallpaperDefault
 * DESCRIPTION
 *  This function is to set sub wallpaper to default one
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void
 *  b(?)        [IN]            ImageId
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetRstSubWallpaperDefault(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_cntx_p->curtSubWpID = RstGetWallpaperSubImgIdDefault();    /* RstGetWallpaperImgIdDefault(); */
    mmi_dispchar_set_img_id(NVRAM_SETWALLPAPER_SUB, &(g_phnset_cntx_p->curtSubWpID));

    SUBLCD_SetIdleScreenWallpaperID(g_phnset_cntx_p->curtSubWpID);
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_RST_SUBWP_DEFAULT,
                         g_phnset_cntx_p->curtSubWpID);

    if (!srv_bootup_is_booting())
    {
        DispIdleScrWPBadFilePopup();
    }

}
#endif /* __MMI_SUB_WALLPAPER__ */ 


/*****************************************************************************
 * FUNCTION
 *  PhnsetReadWallpaper
 * DESCRIPTION
 *  This function is to Read wallpaper from Nvram, and set as current wallpaper
 *  Functionality: Referenced at InitNvramData when bootup
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void *
 *  b(?)        [IN]            
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetReadWallpaper(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#ifdef __MMI_FILE_MANAGER__
    S16 error;
#endif
    PHNSET_TYPE_DISP type;
    phnset_wpss_type_enum temp_type = g_phnset_cntx_p->wpss_type;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP;

    mmi_dispchar_get_img_id(NVRAM_FUNANDGAMES_SETWALLPAPER, &(g_phnset_cntx_p->curtWpID));

    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_READ_WP_ID, g_phnset_cntx_p->curtWpID);

    if ((type = PhnsetGetDisplayType(g_phnset_cntx_p->curtWpID)) == PHNSET_TYPE_DISP_INVALID)
    {

        PhnsetRstWallpaperDefault();
    }
#ifdef __MMI_FILE_MANAGER__
    else if (type == PHNSET_TYPE_DISP_USER)
    {
//        ReadRecord(NVRAM_EF_WPSS_FILENAME_LID, 1, &phnset_wpss_filename, sizeof(phnset_wpss_filename), &error);
        ReadRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 1, &g_phnset_wallpaper_actual_filename, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);        
        if (error == NVRAM_READ_SUCCESS ||
            mmi_fmgr_util_file_limit_check(FMGR_LIMIT_WALLPAPER, (PS8) g_phnset_wallpaper_actual_filename.filename, &error_str_ptr))
        {
            g_phnset_cntx_p->isShort = g_phnset_wallpaper_actual_filename.is_short;
            PhnsetSetWallpaperByFileName((S8*) g_phnset_wallpaper_actual_filename.filename);
        }
        else
        {
            memset(&g_phnset_wallpaper_actual_filename, 0, sizeof(g_phnset_wallpaper_actual_filename));

            PhnsetRstWallpaperDefault();
        }
    }
#endif /* __MMI_FILE_MANAGER__ */    
    else
    {
        PhnsetSetWallpaperByImgID(g_phnset_cntx_p->curtWpID);
    }

#ifdef __MMI_SUB_WALLPAPER__

    g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_SUB_WP;

    mmi_dispchar_get_img_id(NVRAM_SETWALLPAPER_SUB, &(g_phnset_cntx_p->curtSubWpID));

    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_READ_SUBWP_ID, g_phnset_cntx_p->curtSubWpID);

    if ((type = PhnsetGetDisplayType(g_phnset_cntx_p->curtSubWpID)) == PHNSET_TYPE_DISP_INVALID)
    {

        PhnsetRstSubWallpaperDefault();
    }
#ifdef __MMI_FILE_MANAGER__
    else if (type == PHNSET_TYPE_DISP_USER)
    {
        ReadRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 2, &g_phnset_wallpaper_sub_filename, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);        
//        ReadRecord(NVRAM_EF_WPSS_FILENAME_LID, 3, &phnset_wpss_sub_filename, sizeof(phnset_wpss_sub_filename), &error);
        if (error == NVRAM_READ_SUCCESS)
        {
            SUBLCD_SetIdleScreenWallpaperName((UI_string_type) g_phnset_wallpaper_sub_filename.filename);
        }
        else
        {
            memset(&g_phnset_wallpaper_sub_filename, 0, sizeof(g_phnset_wallpaper_sub_filename));

            PhnsetRstSubWallpaperDefault();

            SUBLCD_SetIdleScreenWallpaperID(g_phnset_cntx_p->curtWpID);
        #ifdef __USB_IN_NORMAL_MODE__            
            if (mmi_usb_is_leaving_ms_mode())
                SUBLCD_UpdateWallpaper();
        #endif
        }
    }
#endif /* __MMI_FILE_MANAGER__ */    
    else
    {
        SUBLCD_SetIdleScreenWallpaperID(g_phnset_cntx_p->curtSubWpID);
    }

#endif /* __MMI_SUB_WALLPAPER__ */ 

    g_phnset_cntx_p->wpss_type = temp_type;

}


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetFileNamePointer
 * DESCRIPTION
 *  To find the pointer of path
 * PARAMETERS
 *  path        [IN]            
 *  a(?)        [IN/OUT]        Void *
 *  b(?)        [IN]            
 * RETURNS
 *  PS8 wallpaper name string pointer
 *****************************************************************************/
PS8 PhnsetGetFileNamePointer(PS8 path)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 len;
    U16 deter = 0x005C; /* '\' */
    S16 *p = (S16*) path;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    len = (U16) mmi_ucs2strlen(path);
    for (; len > 0; len--)
    {
        if (*(p + len) == deter)
        {
            return (PS8) (p + len + 1);
        }
    }

    return NULL;
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetCurWallpaperName
 * DESCRIPTION
 *  This function is to get current name string pointer of wallpaper
 *  Functionality: ex: Referenced by hint windows
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void *
 *  b(?)        [IN]            
 * RETURNS
 *  PS8 wallpaper name string pointer
 *****************************************************************************/
PS8 PhnsetGetCurWallpaperName(void)
{
#ifdef __MMI_FILE_MANAGER__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->curtWpID == 0)
    {
        #if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
        #endif            
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_GET_CUR_WP_NAME, g_phnset_wallpaper_actual_filename.filename);
            
            return PhnsetGetFileNamePointer((PS8) g_phnset_wallpaper_actual_filename.filename);
        }
    }
    else
#endif /* __MMI_FILE_MANAGER__ */ 
        return PhnsetGetWallpaperNameById(g_phnset_cntx_p->curtWpID);
}

#ifdef __MMI_SUB_WALLPAPER__


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetCurSubWallpaperName
 * DESCRIPTION
 *  This function is to get current name string pointer of sublcd wallpaper
 *  Functionality: ex: Referenced by hint windows
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        Void *
 *  b(?)        [IN]            
 * RETURNS
 *  PS8 wallpaper name string pointer
 *****************************************************************************/
PS8 PhnsetGetCurSubWallpaperName(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->curtSubWpID == 0)
    {
#if 0        
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif            
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_GET_CUR_SUBWP_NAME, g_phnset_wallpaper_sub_filename.filename);

            return PhnsetGetFileNamePointer((PS8) g_phnset_wallpaper_sub_filename.filename);
        }

    }
    else
    {
        return PhnsetGetWallpaperNameById(g_phnset_cntx_p->curtSubWpID);
    }
}
#endif /* __MMI_SUB_WALLPAPER__ */ 


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetWallpaperNameById
 * DESCRIPTION
 *  This function is to translate image ID to name string pointer
 *  Functionality: ex: Referenced by hint windows
 * PARAMETERS
 *  Id          [IN]            
 *  a(?)        [IN/OUT]        
 *  b(?)        [IN]            U16 image ID
 * RETURNS
 *  Wallpaper Name as PS8 passed as U16 as its ID
 *****************************************************************************/
PS8 PhnsetGetWallpaperNameById(U16 Id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    PS8 pstr = NULL;
    U32 strID;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (Id >= IMG_ID_PHNSET_WP_START && Id <= IMG_ID_PHNSET_WP_MAX)
    {
        /* System Wallpaper Range */
        strID = STR_ID_PHNSET_DISPCHAR_IMGID_START + (Id - IMG_ID_PHNSET_WP_START);
        pstr = GetString((U16) strID);
    }
#ifdef __MMI_SUB_WALLPAPER__
    else if (Id >= IMG_ID_PHNSET_SUB_WP_START && Id <= IMG_ID_PHNSET_SUB_WP_MAX)
    {
        strID = STR_ID_PHNSET_DISPCHAR_IMGID_START + (Id - IMG_ID_PHNSET_SUB_WP_START);
        pstr = GetString((U16) strID);
    }
#endif /* __MMI_SUB_WALLPAPER__ */ 
#ifndef __MMI_UI_TECHNO_IDLESCREEN_BAR__    
#ifdef __MMI_ANALOG_CLOCK__
    else if (Id == IMG_ID_DISPCHAR_ANALOG_CLK)
    {
        /* Analog Clock Wallpaper */
        strID = STR_ID_PHNSET_DISPCHAR_ANALOG;
        pstr = GetString((U16) strID);
    }
#endif /* __MMI_ANALOG_CLOCK__ */ 

#ifdef __MMI_DIGITAL_CLOCK__
    else if (Id == IMG_ID_DISPCHAR_DIGITAL_CLK)
    {
        /* Digital Clock Wallpaper */
        strID = STR_ID_PHNSET_DISPCHAR_DIGITAL;
        pstr = GetString((U16) strID);
    }
#endif /* __MMI_DIGITAL_CLOCK__ */ 
#endif /* !__MMI_UI_TECHNO_IDLESCREEN_BAR__ */

    else if (Id == IMG_ID_DISPCHAR_THEME_WALLPAPER)
    {
        /* Theme Wallpaper */
        strID = STR_ID_DISPCHAR_THEME_WALLPAPER;
        pstr = GetString((U16) strID);
    }

#ifdef __MMI_SWFLASH__
    else if (Id >= IMG_ID_DISPCHAR_SWFLASH_START && Id <= IMG_ID_DISPCHAR_SWFLASH_MAX)
    {
        strID = STR_ID_DISPCHAR_SWFLASH_START + (Id - IMG_ID_DISPCHAR_SWFLASH_START);
        pstr = GetString((U16) strID);
    }
#endif /* __MMI_SWFLASH__ */
#ifdef __MMI_AVATAR__
    else if (Id == IMG_ID_DISPCHAR_AVATAR_WALLPAPER)
    {
        U32 avatar_id;
        U32 serial_num;
        dispchar_get_current_avatar_id(Id, &avatar_id, &serial_num);
        mmi_avater_get_name_by_avatarid((U32)avatar_id, (PS8)phnset_dispchar_temp);
        pstr = (PS8)phnset_dispchar_temp;
    }
#endif /* __MMI_AVATAR__ */

    return pstr;

}


/*****************************************************************************
 * FUNCTION
 *  PhnsetSetWallpaperByImgID
 * DESCRIPTION
 *  This function is to set current wallpaper using index by AT command
 * PARAMETERS
 *  imgID       [IN]            
 *  a(?)        [IN/OUT]        
 *  b(?)        [IN]            U16 image ID
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetSetWallpaperByImgID(U16 imgID)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        g_phnset_cntx_p->curtWpID = imgID;
        mmi_dispchar_set_img_id(NVRAM_FUNANDGAMES_SETWALLPAPER, &(g_phnset_cntx_p->curtWpID));
        SetIdleScreenWallpaperID(g_phnset_cntx_p->curtWpID, MMI_FALSE);
    
    #if (defined(__MMI_SWFLASH__ ) || defined(__MMI_AVATAR__))&& defined(__MMI_WALLPAPER_ON_BOTTOM__)
        if (PhnsetGetDisplayType(g_phnset_cntx_p->curtWpID) == PHNSET_TYPE_DISP_SWFLASH ||
            PhnsetGetDisplayType(g_phnset_cntx_p->curtWpID) == PHNSET_TYPE_DISP_AVATAR)
        {
            U16 default_id;
            mmi_dispchar_get_img_id(RESTORE_DEFAULT_FUNANDGAMES_SETWALLPAPER, &(default_id));            
            SetListWallpaperID(default_id);
        }
    #endif /* __MMI_SWFLASH__ */
    
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SET_WP_ID, g_phnset_cntx_p->curtWpID);

        if (g_idle_context.IsOnIdleScreen)
        {
            EntryIdleScreen();
        }

    }
#ifdef __MMI_SUB_WALLPAPER__
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP)
    {
        g_phnset_cntx_p->curtSubWpID = imgID;
        mmi_dispchar_set_img_id(NVRAM_SETWALLPAPER_SUB, &(g_phnset_cntx_p->curtSubWpID));
        SUBLCD_SetIdleScreenWallpaperID(g_phnset_cntx_p->curtSubWpID);

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SET_SUBWP_ID, g_phnset_cntx_p->curtSubWpID);

    }
#endif /* __MMI_SUB_WALLPAPER__ */ 
    else
    {
        MMI_ASSERT(0);
    }

    g_phnset_cntx_p->isCorrectSet = 1;

}


#ifdef __MMI_FILE_MANAGER__


/*****************************************************************************
 * FUNCTION
 *  PhnsetSetWallpaperByFileName
 * DESCRIPTION
 *  This function is to set current wallpaper using index by AT command
 * PARAMETERS
 *  path        [?]             
 *  a(?)        [IN/OUT]        
 *  b(?)        [IN]            U16 image ID
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetSetWallpaperByFileName(S8 *path)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_cntx_p->isCorrectSet = 1;

#if defined(__MMI_OP11_HOMESCREEN_0301__) || defined(__MMI_OP11_HOMESCREEN_0302__)
    mmi_op11_hs32_set_done_flag();
#endif

#ifdef __MMI_FILE_MANAGER__
    save_cache_flag = MMI_FALSE;
#endif

    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        if (g_phnset_cntx_p->isShort)
        {
            g_phnset_wallpaper_actual_filename.is_short= 1;
        }
        else
        {
            g_phnset_wallpaper_actual_filename.is_short = 0;
        }

        g_phnset_cntx_p->curtWpID = 0;

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SET_WP_NAME,
                             g_phnset_wallpaper_actual_filename.is_short, g_phnset_wallpaper_actual_filename.filename);

        mmi_ucs2cpy((S8*) g_phnset_wallpaper_actual_filename.filename, (S8*) path);
        mmi_dispchar_set_img_id(NVRAM_FUNANDGAMES_SETWALLPAPER, &(g_phnset_cntx_p->curtWpID));
        WriteRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 1, &g_phnset_wallpaper_actual_filename, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);        
//        WriteRecord(NVRAM_EF_WPSS_FILENAME_LID, 1, &phnset_wpss_filename, sizeof(phnset_wpss_filename), &error);
        /* SetIdleScreenWallpaperName((UI_string_type) phnset_wpss_filename.wallpaper); */
        SetIdleScreenWallpaperName((UI_string_type) phnset_wp_default_file);

    #if defined(__MMI_SWFLASH__ ) && defined(__MMI_WALLPAPER_ON_BOTTOM__)
        if ((g_phnset_cntx_p->curtWpID == 0 && srv_fmgr_types_find_group_by_filename_str((WCHAR*) g_phnset_wallpaper_actual_filename.filename) == FMGR_GROUP_SWFLASH) ||
            (g_phnset_cntx_p->curtWpID != 0 && PhnsetGetDisplayType(g_phnset_cntx_p->curtWpID) == PHNSET_TYPE_DISP_SWFLASH))
        {
            U16 default_id;
            mmi_dispchar_get_img_id(RESTORE_DEFAULT_FUNANDGAMES_SETWALLPAPER, &(default_id));            
            SetListWallpaperID(default_id);
        }
    	else
    #endif /* __MMI_SWFLASH__ */


        if (g_idle_context.IsOnIdleScreen)
        {
            EntryIdleScreen();
        }
    }
#ifdef __MMI_SUB_WALLPAPER__
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP)
    {
        if (g_phnset_cntx_p->isShort)
        {
            g_phnset_wallpaper_sub_filename.is_short = 1;
        }
        else
        {
            g_phnset_wallpaper_sub_filename.is_short = 0;
        }

        g_phnset_cntx_p->curtSubWpID = 0;

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SET_SUBWP_NAME,
                             g_phnset_wallpaper_sub_filename.is_short, g_phnset_wallpaper_sub_filename.filename);

        mmi_ucs2cpy((S8*) g_phnset_wallpaper_sub_filename.filename, (S8*) path);
        mmi_dispchar_set_img_id(NVRAM_SETWALLPAPER_SUB, &(g_phnset_cntx_p->curtSubWpID));
//        WriteRecord(NVRAM_EF_WPSS_FILENAME_LID, 3, &phnset_wpss_sub_filename, sizeof(phnset_wpss_sub_filename), &error);
        WriteRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 2, &g_phnset_wallpaper_sub_filename, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);        
        SUBLCD_SetIdleScreenWallpaperName((UI_string_type) path);
        SUBLCD_UpdateWallpaper();
    }
#endif /* __MMI_SUB_WALLPAPER__ */ 
    else
    {
        MMI_ASSERT(0);
    }
}


#endif /* __MMI_FILE_MANAGER__ */


/*****************************************************************************
 * FUNCTION
 *  PhnsetSetDisplayFromAT
 * DESCRIPTION
 *  This function is to set current wallpaper using index by AT command
 * PARAMETERS
 *  idx         [IN]            
 *  type        [IN]            
 *  a(?)        [IN/OUT]        
 *  b(?)        [IN]            U16 image ID
 * RETURNS
 *  void
 *****************************************************************************/
BOOL PhnsetSetDisplayFromAT(U8 idx, U8 type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 SysWpIDList[MAX_WALLPAPER_IMG];
    U8 max_idx = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if !defined(__MMI_DUAL_SIM_MASTER__)
    if (srv_sim_ctrl_is_available(MMI_SIM1))
#else   /* __MMI_DUAL_SIM_MASTER__ */
    if (srv_sim_ctrl_is_available(MMI_SIM1) || srv_sim_ctrl_is_inserted(MMI_SIM2))
#endif  /* __MMI_DUAL_SIM_MASTER__ */
    {
		mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_DONE), MMI_EVENT_SUCCESS, GRP_ID_ROOT, NULL);
    
        switch (type)
        {
            case MMI_PHNSET_TYPE_WP:
        #ifdef __MMI_SUB_WALLPAPER__
            case MMI_PHNSET_TYPE_SUB_WP:
        #endif 
            {
                phnset_wpss_type_enum tmp_type = g_phnset_cntx_p->wpss_type;

                g_phnset_cntx_p->wpss_type = (phnset_wpss_type_enum) type;

                max_idx = PhnsetConstSysWallpaperList(NULL, SysWpIDList, NULL);

                g_phnset_cntx_p->wpss_type = tmp_type;

                if (idx < max_idx)  /* unsigned comparison with 0 is always true: '>=' */
                {

                    g_phnset_cntx_p->curtWpID = SysWpIDList[idx];
                    mmi_dispchar_set_img_id(NVRAM_FUNANDGAMES_SETWALLPAPER, &(g_phnset_cntx_p->curtWpID));
                    mmi_dispchar_set_img_id(RESTORE_DEFAULT_FUNANDGAMES_SETWALLPAPER, &(g_phnset_cntx_p->curtWpID));

                    SetIdleScreenWallpaperID(g_phnset_cntx_p->curtWpID, MMI_FALSE);

                    if (g_idle_context.IsOnIdleScreen)
                    {
                        EntryIdleScreen();
                    }
                }
                else
                {
                    return MMI_FALSE;
                }
            }
                break;
            case MMI_PHNSET_TYPE_SS:
            {
                max_idx = PhnsetConstSysScrSvrList(NULL, SysWpIDList, NULL);
                if (idx < max_idx)  /* unsigned comparison with 0 is always true: '>=' */
                {

                    g_phnset_cntx_p->curSsID = SysWpIDList[idx];
                    mmi_dispchar_set_img_id(NVRAM_CURRENT_SCREENSVER_ID, &(g_phnset_cntx_p->curSsID));
                    mmi_dispchar_set_img_id(RESTORE_DEFAULT_CURRENT_SCREENSVER_ID, &(g_phnset_cntx_p->curSsID));
                }
                else
                {
                    return MMI_FALSE;
                }

            }
                break;
        #ifdef __MMI_POWER_ON_OFF_DISPLAY__
            case MMI_PHNSET_TYPE_PWRON:
            case MMI_PHNSET_TYPE_PWROFF:
            {
                phnset_wpss_type_enum tmp_type = g_phnset_cntx_p->wpss_type;

                g_phnset_cntx_p->wpss_type = (phnset_wpss_type_enum) type;

                max_idx = PhnsetConstSysPwrOnOffList(NULL, SysWpIDList, NULL);

                g_phnset_cntx_p->wpss_type = tmp_type;

                if (idx < max_idx)  /* unsigned comparison with 0 is always true: '>=' */
                {
                    if (type == MMI_PHNSET_TYPE_PWRON)
                    {
                        g_phnset_cntx_p->curtPwrOnID = SysWpIDList[idx];
                        mmi_dispchar_set_img_id(NVRAM_CURRENT_POWER_ON_DISPLAY, &(g_phnset_cntx_p->curtPwrOnID));
                        mmi_dispchar_set_img_id(NVRAM_RESTORE_POWER_ON_DISPLAY, &(g_phnset_cntx_p->curtPwrOnID));
                    }
                    else
                    {
                        g_phnset_cntx_p->curtPwrOffID = SysWpIDList[idx];
                        mmi_dispchar_set_img_id(NVRAM_CURRENT_POWER_OFF_DISPLAY, &(g_phnset_cntx_p->curtPwrOffID));
                        mmi_dispchar_set_img_id(NVRAM_RESTORE_POWER_OFF_DISPLAY, &(g_phnset_cntx_p->curtPwrOffID));
                    }

                }
                else
                {
                    return MMI_FALSE;
                }

            }
                break;
        #endif /* __MMI_POWER_ON_OFF_DISPLAY__ */ 
        }
    }
    return MMI_TRUE;

}


/*****************************************************************************
 * FUNCTION
 *  PhnsetGetATDisplayBound
 * DESCRIPTION
 *  This function is to get index boundary by AT command
 * PARAMETERS
 *  void
 *  a(?)        [IN/OUT]        
 *  b(?)        [IN]            U16 image ID
 * RETURNS
 *  U8 boundary
 *****************************************************************************/
U8 PhnsetGetATDisplayBound(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return MMI_PHNSET_TYPE_MAX + 3;
}


/*****************************************************************************
 * FUNCTION
 *  PhnsetIsWPCurrentTheme
 * DESCRIPTION
 *  To check if the wallpaper is the current theme.
 * PARAMETERS
 *  void
 * RETURNS
 *  
 *****************************************************************************/
BOOL PhnsetIsWPCurrentTheme(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->curtWpID == IMG_ID_DISPCHAR_THEME_WALLPAPER)
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}


#ifdef __USB_IN_NORMAL_MODE__
/*****************************************************************************
 * FUNCTION
 *  PhnsetWPUseDefault
 * DESCRIPTION
 *  Use default build-in wallpaper
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void PhnsetWPUseDefault(void)
{
#ifdef __MMI_FILE_MANAGER__

    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    PHNSET_TYPE_DISP type;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((type = PhnsetGetDisplayType(g_phnset_cntx_p->curtWpID)) == PHNSET_TYPE_DISP_USER
        && (mmi_usb_check_path_exported((S8*) g_phnset_wallpaper_actual_filename.filename)))
    {
        g_phnset_cntx_p->curtWpID = RstGetWallpaperImgIdDefault();
        SetIdleScreenWallpaperID(g_phnset_cntx_p->curtWpID, MMI_TRUE);
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_WP_USE_DEFAULT, g_phnset_cntx_p->curtWpID);
    }
#ifdef __MMI_SUB_WALLPAPER__
    if ((type = PhnsetGetDisplayType(g_phnset_cntx_p->curtSubWpID)) == PHNSET_TYPE_DISP_USER
        && (mmi_usb_check_path_exported((S8*) g_phnset_wallpaper_sub_filename.filename)))
    {
        g_phnset_cntx_p->curtSubWpID = RstGetWallpaperSubImgIdDefault();
        SUBLCD_SetIdleScreenWallpaperID(g_phnset_cntx_p->curtSubWpID);
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_SUBWP_USE_DEFAULT, g_phnset_cntx_p->curtSubWpID);
    }
#endif /* __MMI_SUB_WALLPAPER__ */ 
#endif /* __MMI_FILE_MANAGER__ */
}
#endif /* __USB_IN_NORMAL_MODE__ */ 


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_check_themeid_wallpaper
 * DESCRIPTION
 *  Check img ID is theme or not
 * PARAMETERS
 *  void
 * RETURNS
 *  BOOL
 *****************************************************************************/
MMI_BOOL mmi_phnset_check_themeid_wallpaper(U16 imgID)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (imgID == IMG_ID_DISPCHAR_THEME_WALLPAPER)
        return MMI_TRUE;

    return MMI_FALSE;
}


#if defined(__MMI_OP11_HOMESCREEN_0301__) || defined(__MMI_OP11_HOMESCREEN_0302__) || defined(__MMI_OP11_HOMESCREEN__)
/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_entry_wallpaper_main
 * DESCRIPTION
 *  Entry wallpaper main menu for other application
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_entry_wallpaper_main(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP;

#if (defined (__DAILY_WALLPAPER__) )
    /* Go to menu with 2 items: Fix, Rotate */
    mmi_phnset_entry_wallpaper_select_menu(GRP_ID_ROOT);
    
#elif (defined(__MMI_FILE_MANAGER__) && !defined(__MMI_DISPLAY_CHAR_HIDE_MENU_FROM_FILE__) )
    /* Go to menu with 2 items: System, Download */
    mmi_phnset_entry_wallpaper_select_menu(GRP_ID_ROOT);
#else 
    /* Direct enter system wallpaper list menu */
    EntryPhnsetWallpaperSys(GRP_ID_ROOT);
#endif 
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_entry_wallpaper_select_menu
 * DESCRIPTION
 *  Entry menu with 2 items: system, user defined 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_entry_wallpaper_select_menu(mmi_id parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_id menucui_gid;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!parent_gid)
	{
	    parent_gid = GRP_ID_ROOT;
	}
    if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_MAIN))
	{
	    mmi_frm_group_close(GRP_ID_WALLPAPER_MAIN);
	}
    mmi_frm_group_create(parent_gid, GRP_ID_WALLPAPER_MAIN, mmi_phnset_wallpaper_select_menu_proc, NULL);
    mmi_frm_group_enter(GRP_ID_WALLPAPER_MAIN, MMI_FRM_NODE_SMART_CLOSE_FLAG);
    menucui_gid = cui_menu_create(GRP_ID_WALLPAPER_MAIN, CUI_MENU_SRC_TYPE_RESOURCE, CUI_MENU_TYPE_FROM_RESOURCE, MENU_SETTING_WALLPAPER, MMI_FALSE, NULL);
    cui_menu_run(menucui_gid);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_select_menu_proc
 * DESCRIPTION
 *  Proc function for wallpaper menu in OP11 Home screen 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_select_menu_proc(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    cui_menu_event_struct *menu_event = (cui_menu_event_struct*)param;
    mmi_id menucui_gid = mmi_frm_group_get_active_id();
     
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (cui_menu_is_menu_event(param->evt_id))
	{
        if (menu_event->evt_id == EVT_ID_CUI_MENU_CLOSE_REQUEST)
    	{
            cui_menu_close(menucui_gid);
    	}
        else
        {
        	return mmi_phnset_wallpaper_sub_menu_handler(menu_event, GRP_ID_WALLPAPER_MAIN);            
        }    	
	}
    return MMI_RET_OK;
}
#endif /* defined( __MMI_OP11_HOMESCREEN_0301__) || defined(__MMI_OP11_HOMESCREEN_0302__) || defined(__MMI_OP11_HOMESCREEN__) */

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_speedup
 * DESCRIPTION
 *  Check img ID is theme or not
 * PARAMETERS
 *  void
 * RETURNS
 *  BOOL
 *****************************************************************************/
void mmi_phnset_save_wallpaper_to_speedup(void)
{
#ifdef __MMI_FILE_MANAGER__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MMI_BOOL ret;
    GDI_HANDLE wplayer;
    U16 cache_imgtype;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_PHNSET_WP_SPEEDUP_FUNCTION);

    if (save_cache_flag)
        return;

    ret = mmi_cat33_get_cache_wallpaper_info(idle_screen_wallpaper_ID, 	idle_screen_wallpaper_name, &wplayer, &cache_imgtype);

    if (wplayer == GDI_ERROR_HANDLE)
        return;

    {
        FS_HANDLE dir_ret;

        dir_ret = FS_Open(PHNSET_PREDEFINED_WP_PATH, FS_OPEN_DIR | FS_READ_ONLY);
        if (dir_ret < 0)
        {
            dir_ret = FS_CreateDir(PHNSET_PREDEFINED_WP_PATH);
            if (dir_ret < 0)
            {
                return;
            }
            else
            {
                dir_ret = 0;
            }
        }
        else
        {
            FS_Close(dir_ret);
            dir_ret = 0;
        }
    }

    if (ret == MMI_TRUE)
    {
        GDI_RESULT save_result;
        S32 ret = 0;
        
        if (cache_imgtype == GDI_IMAGE_TYPE_DEVICE_BMP_FILE)
        {
            save_result = gdi_layer_save_pbm_file(wplayer, (S8*)PHNSET_PREDEFINED_WP_PATH_PBM);

            if (0 <= save_result)
            {
                idle_screen_wallpaper_name = (S8*) PHNSET_PREDEFINED_WP_PATH_PBM;
                gdi_anim_stop_all_by_layer(wplayer);
            }
            else
            {
                ret = mmi_phnset_del_file((WCHAR *)PHNSET_PREDEFINED_WP_PATH_PBM);
            }
        }
        else if (cache_imgtype == GDI_IMAGE_TYPE_JPG_FILE)   
        {
            save_result = gdi_layer_save_jpeg_file(wplayer, (S8*) PHNSET_PREDEFINED_WP_PATH_JPG);

            if (0 <= save_result)
            {
                idle_screen_wallpaper_name = (S8*) PHNSET_PREDEFINED_WP_PATH_JPG;
                gdi_anim_stop_all_by_layer(wplayer);
            }
            else
            {
                ret = mmi_phnset_del_file((WCHAR *)PHNSET_PREDEFINED_WP_PATH_JPG);
            }
        }
    }

    save_cache_flag = MMI_TRUE;
#endif /* __MMI_FILE_MANAGER__ */

}

#ifdef __MMI_FILE_MANAGER__

#ifdef __DRM_SUPPORT__
/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_drm_check
 * DESCRIPTION
 *  Perform DRM check on input file 
 * PARAMETERS
 *  
 * RETURNS
 *  static U8
 *****************************************************************************/
U8 mmi_phnset_wallpaper_drm_check(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 res_type;
    U8 permission;
    FS_HANDLE handle;
    MMI_BOOL is_perm = MMI_TRUE;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    res_type = srv_fmgr_types_find_group_by_filename_str((WCHAR*)phnset_dispchar_strp);
    
    if (res_type == FMGR_GROUP_IMAGE)
    {
        permission = DRM_PERMISSION_DISPLAY;
    }
    else if (res_type == FMGR_GROUP_VIDEO)
    {
        permission = DRM_PERMISSION_PLAY;
    }
    else 
    {
        permission = DRM_PERMISSION_NONE;
    }
    
    if (permission != DRM_PERMISSION_NONE)
    {
        handle = DRM_open_file((PU16)phnset_dispchar_strp, FS_READ_ONLY, permission);
        
        if (handle >= FS_NO_ERROR)
        {
            is_perm = DRM_validate_forward_rule(handle, permission);
            DRM_close_file(handle);
        }
    }
    
    if (!is_perm)
    {
        error_str_ptr = (PS8)GetString(STR_GLOBAL_DRM_PROHIBITED);
        PhnsetWpUsrDefFreeBuf();
        return PHNSET_WP_SS_SET_DRM_CHECK_FAIL;
    }    
    return PHNSET_WP_SS_SET_NO_ERROR;
}
#endif


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_timeout
 * DESCRIPTION
 *  time out handler for waiting screen
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_copy_wpss_timeout(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_019);

    phnset_waiting_timeout = MMI_TRUE;

    StopTimer(MMI_PHNSET_COPY_WAIT_TIMER);
    if (mmi_frm_scrn_is_present(GRP_ID_WALLPAPER_PREVIEW, SCR_IDLE_SCR_DISP_WPSS_WAITING, MMI_FRM_NODE_ALL_FLAG))
	{
        mmi_frm_scrn_set_leave_proc(GRP_ID_WALLPAPER_PREVIEW, SCR_IDLE_SCR_DISP_WPSS_WAITING, NULL);	
	}

    /* receive copy response before time out and remove waiting screen */
    if (phnset_waiting_receive_rsp == MMI_TRUE)
    {
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_020);
        mmi_phnset_copy_wpss_refresh_screen();
    }

}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_del_file
 * DESCRIPTION
 *  phone setup delete file function
 * PARAMETERS
 *  void
 * RETURNS
 *  file_path
 *****************************************************************************/
static S32 mmi_phnset_del_file(const WCHAR* file_path)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 attr = 0;
    U8 path_asc[SRV_FMGR_PATH_MAX_LEN + 1];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    attr = FS_GetAttributes((const WCHAR*) file_path);
    if (attr & FS_ATTR_READ_ONLY)
    {
        FS_SetAttributes((const WCHAR*) file_path, (U8) (attr & ~(FS_ATTR_READ_ONLY)));
    }

    mmi_ucs2_to_asc((PS8) path_asc, (PS8) file_path);

    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_021, path_asc);

    return FS_Delete((const WCHAR*)file_path);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_check_device
 * DESCRIPTION
 *  check device status and storage before copy image or video file to root
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_copy_wpss_check_device(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 process_result;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_wp_ss_set_callback = mmi_phnset_wallpaper_set_from_menu_finished;

    process_result = mmi_phnset_copy_wallpaper_screensaver();    
    switch (process_result)
    {
	case PHNSET_WP_SS_SET_DISK_SIZE_NOT_ENOUGH:
        /* display error pop up and return file list screen */
        mmi_popup_display_simple((WCHAR*)GetString(FMGR_FS_DISK_FULL_TEXT),MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
		break;
    case PHNSET_WP_SS_SET_PREPARE_FOLDER_FAIL:
    case PHNSET_WP_SS_SET_PREPARE_FILE_FAIL:
    case PHNSET_WP_SS_SET_GET_DISK_INFO_FAIL:
        mmi_popup_display_simple((WCHAR*)GetString(STR_GLOBAL_FAILED_TO_SAVE), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
        break;
	default:
		break;
    }
        
    if (process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        PhnsetWpUsrDefFreeBuf();
	mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW);
        return;
    }

    /*  start a timer to display a waiting screen */    
    phnset_waiting_timeout = MMI_FALSE;    
    mmi_phnset_copy_wpss_entry_waiting_entry();
    StartTimer(MMI_PHNSET_COPY_WAIT_TIMER, 2000, mmi_phnset_copy_wpss_timeout);    
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wallpaper_screensaver
 * DESCRIPTION
 *  Copy Wallpaper and Screen saver file to system folder and save the setting 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static U8 mmi_phnset_copy_wallpaper_screensaver(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 path_ucs2[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
    S16 drive;
    U8 process_result;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_022);

    drive = SRV_FMGR_PUBLIC_DRV;

    process_result = mmi_phnset_wallpaper_prepare_folder(drive);
    if( process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return process_result;
    }

    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        g_phnset_wallpaper_default_file_1.is_short = 0;
        g_phnset_wallpaper_default_file_2.is_short = 0;        
//        phnset_wpss_default_file_1.isWPShort = 0;
//        phnset_wpss_default_file_2.isWPShort = 0;
    }
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
    {
        g_phnset_screensaver_default_file_1.is_short = 0;
        g_phnset_screensaver_default_file_2.is_short = 0; 
//         g_phnset_screensaver_default_file_1.is_dirty = 0;
//        phnset_wpss_default_file_2.isSSShort = 0;
    }

    mmi_phnset_init_default_file();
    
    mmi_phnset_del_dirty_file();

    /* disk free space is OK or old file size more */
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_029);

    process_result = mmi_phnset_wallpaper_prepare_file_path(path_ucs2);
    if(process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return process_result;
    }

    process_result = mmi_phnset_wallpaper_check_disk(drive);    
    if(process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return process_result;
    }
        /* set flag not receive response and not time out */
        phnset_waiting_receive_rsp = MMI_FALSE;

        /* use FMT to copy a file */
        g_wp_ss_copy_job_id = srv_fmgr_async_copy(
            (WCHAR*)phnset_dispchar_strp,
            (WCHAR*)path_ucs2,
            SRV_FMGR_ASYNC_FLAG_PRIORITY_FG,
            mmi_phnset_copy_wpss_proc,
            NULL);

        /* If FS error, g_wp_ss_copy_job_id < 0 */
        if(g_wp_ss_copy_job_id < 0)
        {
            file_copy_result_str_id = srv_fmgr_fs_error_get_string(g_wp_ss_copy_job_id);
            return PHNSET_WP_SS_SET_COPY_FILE_FAIL;
        }

    return PHNSET_WP_SS_SET_NO_ERROR;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_proc
 * DESCRIPTION
 *  Proc function for copy file 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_copy_wpss_proc(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (param->evt_id == EVT_ID_SRV_FMGR_ASYNC_DONE)
	{
        srv_fmgr_async_done_event_struct *done_event = (srv_fmgr_async_done_event_struct*)param;
        mmi_phnset_copy_wpss_rsp(done_event);
	
	}
}

void mmi_phnset_copy_wpss_entry_waiting_exit_hdlr(void)
{
    mmi_frm_end_scenario(MMI_SCENARIO_ID_HIGH_SCRN);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_entry_waiting
 * DESCRIPTION
 *  Copy image or video file to root
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_copy_wpss_entry_waiting_entry(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_038);
    //mmi_frm_start_scenario(MMI_SCENARIO_ID_HIGH_SCRN);
    mmi_frm_scrn_enter(
        GRP_ID_WALLPAPER_PREVIEW,
        SCR_IDLE_SCR_DISP_WPSS_WAITING,
        NULL,
        mmi_phnset_copy_wpss_entry_waiting_entry,
        MMI_FRM_FULL_SCRN);
    
    ShowCategory63Screen(
        (PU8) GetString(STR_GLOBAL_PLEASE_WAIT),
        mmi_get_event_based_image(MMI_EVENT_PROGRESS),
        NULL);

    mmi_frm_scrn_set_leave_proc(GRP_ID_WALLPAPER_PREVIEW, SCR_IDLE_SCR_DISP_WPSS_WAITING, mmi_phnset_copy_wpss_waiting_leave_proc);

    SetKeyHandler(MMI_dummy_function, KEY_END, KEY_EVENT_DOWN);
    
    /* add for Java push */
    //mmi_frm_block_general_interrupt_event(MMI_FRM_INT_MMI_JAVA_TIMEALARM_PUSH);
    //mmi_frm_block_general_interrupt_event(MMI_FRM_INT_MMI_JAVA_PUSH_INSTALL);

}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_waiting_leave_proc
 * DESCRIPTION
 *  Leave proc for waiting screen of wallpaper setting 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_copy_wpss_waiting_leave_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return MMI_RET_PROHIBIT_SCRN_ENTER;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_entry_waiting_exit
 * DESCRIPTION
 *  exit waiting screen after receive response
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_copy_wpss_entry_waiting_exit(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_039);

    /* not receive response and not pop up */
    if ((phnset_waiting_receive_rsp == MMI_FALSE) /* && (POPUP_SCREENID != GetActiveScreenId()) */ )
    {
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_040);
        srv_fmgr_async_abort(g_wp_ss_copy_job_id, MMI_TRUE);
    }
    else
    {
        GenericExitInlineScreen(SCR_IDLE_SCR_DISP_WPSS_WAITING, (FuncPtr)mmi_phnset_copy_wpss_entry_waiting_entry);
    }

}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_save_setting
 * DESCRIPTION
 *  save setting after copy success
 * PARAMETERS
 *  U8 * file_path
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_copy_wpss_save_setting(U8* file_path)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        mmi_ucs2cpy((PS8) phnset_wp_default_file, (PS8) phnset_dispchar_wp_cp_file);

        if ( g_phnset_wallpaper_default_file_1.is_short == 1)
        {
            mmi_ucs2cpy((PS8)g_phnset_wallpaper_default_file_1.filename, (PS8)phnset_wp_default_file);
        }
        else if ( g_phnset_wallpaper_default_file_2.is_short == 1)
        {
            mmi_ucs2cpy((PS8)g_phnset_wallpaper_default_file_2.filename, (PS8)phnset_wp_default_file);
        }

        PhnsetSetWallpaperByFileName((PS8) phnset_dispchar_strp);
#ifdef __MMI_WALLPAPER_ON_BOTTOM__
        wgui_set_wallpaper_change();
#endif 

    }
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
    {
        mmi_ucs2cpy((PS8) phnset_ss_default_file, (PS8) phnset_dispchar_ss_cp_file);

        if ( g_phnset_screensaver_default_file_1.is_short == 1)
        {
            mmi_ucs2cpy((PS8) g_phnset_screensaver_default_file_1.filename, (PS8)phnset_ss_default_file);
        }
        else if ( g_phnset_screensaver_default_file_2.is_short == 1)
        {
            mmi_ucs2cpy((PS8) g_phnset_screensaver_default_file_2.filename, (PS8)phnset_ss_default_file);
        }

        PhnsetSetScrSvrByFileName((PS8) phnset_dispchar_strp);
    }
    WriteRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 3, &g_phnset_wallpaper_default_file_1, sizeof(g_phnset_wallpaper_default_file_1), &error);
    WriteRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 4, &g_phnset_wallpaper_default_file_2, sizeof(g_phnset_wallpaper_default_file_2), &error);
    WriteRecord(NVRAM_EF_SCREENSAVER_FILENAME_LID, 2, &g_phnset_screensaver_default_file_1, sizeof(g_phnset_screensaver_default_file_1), &error);
    WriteRecord(NVRAM_EF_SCREENSAVER_FILENAME_LID, 3, &g_phnset_screensaver_default_file_2, sizeof(g_phnset_screensaver_default_file_2), &error);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_refresh_screen
 * DESCRIPTION
 *  refresh screen after copy file
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_copy_wpss_refresh_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_popup_display_simple((WCHAR*) GetString(STR_GLOBAL_DONE), MMI_EVENT_SUCCESS, GRP_ID_ROOT, NULL);

    if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_PREVIEW))
    {
        mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW);
    }
    if (mmi_frm_group_is_present(GRP_ID_DISPLAY_FMGR_COMMON))
    {
        mmi_frm_group_close(GRP_ID_DISPLAY_FMGR_COMMON);
    }
    if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_MAIN))
    {
        mmi_frm_group_close(GRP_ID_WALLPAPER_MAIN);	
    }
    if (mmi_frm_group_is_present(GRP_ID_SCREENSAVER_MAIN))
    {
	mmi_frm_group_close(GRP_ID_SCREENSAVER_MAIN);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_copy_wpss_entry_waiting
 * DESCRIPTION
 *  Copy image or video file to root
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_copy_wpss_rsp(void *info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_fmgr_async_done_event_struct *msgPtr;
    U16 copy_result;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    msgPtr = (srv_fmgr_async_done_event_struct*) info;
    
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_041, msgPtr->result);

    phnset_waiting_receive_rsp = MMI_TRUE;

    if (msgPtr->result >= 0)
    {
        if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
        {
            mmi_phnset_copy_wpss_save_setting(phnset_dispchar_wp_cp_file);
        }
        else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
        {
            mmi_phnset_copy_wpss_save_setting(phnset_dispchar_ss_cp_file);
        }
        copy_result = PHNSET_WP_SS_SET_NO_ERROR;
    }
    else
    {
        if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
        {
            S32 ret_del;
            
            ret_del = mmi_phnset_del_file((const unsigned short *)phnset_dispchar_wp_cp_file);
            
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_042, ret_del);
        }
        else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
        {
            S32 ret_del;
            
            ret_del = mmi_phnset_del_file((const unsigned short *)phnset_dispchar_ss_cp_file);
            
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_042, ret_del);
        }
        /* Temporay use pointer as a U16 */
        file_copy_result_str_id = (MMI_ID_TYPE)srv_fmgr_fs_error_get_string(msgPtr->result);
        copy_result = PHNSET_WP_SS_SET_COPY_FILE_FAIL;        
    }
    PhnsetWpUsrDefFreeBuf();
    ASSERT(g_phnset_wp_ss_set_callback);

    (*g_phnset_wp_ss_set_callback)(g_phnset_wp_ss_set_userdata, copy_result);
    mmi_phnset_wp_ss_restore_para();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_set_from_menu_finished
 * DESCRIPTION
 *  This function will be call after finish wallpaper setting if setting process
 *  is launched from wallpaper setting menu 
 * PARAMETERS
 *  process_result  [IN]    error code
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_wallpaper_set_from_menu_finished(void* userdata, U16 process_result)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_frm_scrn_is_present(GRP_ID_WALLPAPER_PREVIEW, SCR_IDLE_SCR_DISP_WPSS_WAITING, MMI_FRM_NODE_ALL_FLAG))
	{
        mmi_frm_scrn_set_leave_proc(GRP_ID_WALLPAPER_PREVIEW, SCR_IDLE_SCR_DISP_WPSS_WAITING, NULL);	
	}
    if (process_result == PHNSET_WP_SS_SET_NO_ERROR)
	{
        if (phnset_waiting_timeout == MMI_TRUE)
        {
            mmi_phnset_copy_wpss_refresh_screen();
        }        	
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER__        
        if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    	{
            mmi_phnset_wallpaper_set_vui_live_wallpaper_setting(0);
    	}
#endif
	}
    else
    {
        /* display error pop up with error info and return file list screen */
        if (!srv_ucm_query_call_count(SRV_UCM_CALL_STATE_ALL, SRV_UCM_CALL_TYPE_ALL, NULL))
        {
			mmi_popup_display_simple((WCHAR*) GetString(file_copy_result_str_id), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
        }
        else
        {
            StopTimer(MMI_PHNSET_COPY_WAIT_TIMER);

            if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_PREVIEW))
            {
                mmi_frm_group_close(GRP_ID_WALLPAPER_PREVIEW);
            }
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_get_wpss_postfix
 * DESCRIPTION
 *  get postfix of screen saver and delete copied file in setting folder
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_get_wpss_postfix(U8 *postfix)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    s16 error;
    U8 path_asc[SRV_FMGR_PATH_MAX_LEN + 1];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ReadRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 1, &g_phnset_wallpaper_actual_filename, sizeof(g_phnset_wallpaper_actual_filename), &error);
    ReadRecord(NVRAM_EF_SCREENSAVER_FILENAME_LID, 1, &g_phnset_screensaver_actual_filename, sizeof(g_phnset_screensaver_actual_filename), &error);

    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        mmi_ucs2_to_asc((PS8)path_asc, (PS8)g_phnset_wallpaper_actual_filename.filename);
    }
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
    {
        mmi_ucs2_to_asc((PS8)path_asc, (PS8)g_phnset_screensaver_actual_filename.filename);
    }
    
    mmi_phnset_get_postfix((PU8)postfix, (PU8)path_asc);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_get_postfix
 * DESCRIPTION
 *  get postfix of ucs2 in Buffer
 * PARAMETERS
 *  U8 * postfix
 *  U8 * inBuffer
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phnset_get_postfix_ucs2(U8 *postfix, U8 *inBuffer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *ext = NULL;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((inBuffer == NULL) || (postfix == NULL))
    {
        return;
    }

    /* search the '.' from end of file_name */
    {
        U8 *pos = (U8 *) inBuffer;
        
        while (1)
        {
            if ((*pos == 0) && (*(pos+1) == 0))
                break;

            if (*pos == L'.')
            {
                ext = pos + 2;
            }
            pos += 2;
        }
    }
    
    if (ext)
    {
        mmi_ucs2_to_asc((PS8)postfix, (PS8)ext);
    }
    else
    {
        mmi_ucs2_to_asc((PS8)postfix, (PS8)L"");
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_get_postfix
 * DESCRIPTION
 *  get postfix of asc in Buffer
 * PARAMETERS
 *  U8 * postfix
 *  U8 * inBuffer
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phnset_get_postfix(U8 *postfix, U8 *inBuffer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *ext = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((inBuffer == NULL) || (postfix == NULL))
    {
        return;
    }
    
    /* search the '.' from end of file_name */
    {
        U8 *pos = (PU8) inBuffer;
        
        while (*pos != 0)
        {
            if (*pos == L'.')
            {
                ext = pos + 1;
            }
            pos++;
        }
    }

    if (ext)
    {
        strcpy((PS8)postfix, (PS8)ext);
    }
    else
    {
        strcpy((PS8)postfix, (PS8)"");
    }
}


/*****************************************************************************
* FUNCTION
*  mmi_phnset_del_dirty_file
* DESCRIPTION
*  
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_phnset_del_dirty_file(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/	

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_043);

    if ((g_phnset_wallpaper_default_file_1.is_short == 0) 
        && (mmi_ucs2cmp((PS8)g_phnset_wallpaper_default_file_1.filename, (PS8)L"") != 0))
    {
        FS_HANDLE wp_fh;
        
        wp_fh = FS_Open((const unsigned short *) g_phnset_wallpaper_default_file_1.filename, FS_READ_ONLY);
        
        if (wp_fh >= 0)
        {
            S32 temp_int;
            
            FS_Close(wp_fh);
            temp_int = mmi_phnset_del_file((const unsigned short *) g_phnset_wallpaper_default_file_1.filename);
            
            if (temp_int >= FS_NO_ERROR)
            {
                mmi_ucs2cpy((PS8)g_phnset_wallpaper_default_file_1.filename, (PS8)L"");
            }

            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_044, temp_int);
        }
        else
        {
            if ((wp_fh == FS_FILE_NOT_FOUND) || (wp_fh == FS_PATH_NOT_FOUND))
            {
                mmi_ucs2cpy((PS8)g_phnset_wallpaper_default_file_1.filename, (PS8)L"");
            }
        }

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_045, wp_fh);
    }
    
    if ((g_phnset_wallpaper_default_file_2.is_short == 0)
        && (mmi_ucs2cmp((PS8)g_phnset_wallpaper_default_file_2.filename, (PS8)L"") != 0))
    {
        FS_HANDLE wp_fh;
        
        wp_fh = FS_Open((const unsigned short *) g_phnset_wallpaper_default_file_2.filename, FS_READ_ONLY);
        
        if (wp_fh >= 0)
        {
            S32 temp_int2;
            
            FS_Close(wp_fh);
            temp_int2 = mmi_phnset_del_file((const unsigned short *) g_phnset_wallpaper_default_file_2.filename);
            
            if (temp_int2 >= FS_NO_ERROR)
            {
                mmi_ucs2cpy((PS8)g_phnset_wallpaper_default_file_2.filename, (PS8)L"");
            }

            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_046, temp_int2);
        }
        else
        {            
            if ((wp_fh == FS_FILE_NOT_FOUND) || (wp_fh == FS_PATH_NOT_FOUND))
            {
                mmi_ucs2cpy((PS8)g_phnset_wallpaper_default_file_2.filename, (PS8)L"");
            }
        }

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_047, wp_fh);
    }
    
    if ((g_phnset_screensaver_default_file_1.is_short == 0)
        && (mmi_ucs2cmp((PS8) g_phnset_screensaver_default_file_1.filename, (PS8)L"") != 0))
    {
        FS_HANDLE ss_fh;
        
        ss_fh = FS_Open((const unsigned short *)  g_phnset_screensaver_default_file_1.filename, FS_READ_ONLY);
        
        if (ss_fh >= 0)
        {
            S32 temp_int;
            
            FS_Close(ss_fh);
            
            temp_int = mmi_phnset_del_file((const unsigned short *)  g_phnset_screensaver_default_file_1.filename);
            
            if (temp_int >= FS_NO_ERROR)
            {
                mmi_ucs2cpy((PS8) g_phnset_screensaver_default_file_1.filename, (PS8)L"");
            }

            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_044, temp_int);
        }
        else
        {
            if ((ss_fh == FS_FILE_NOT_FOUND) || (ss_fh == FS_PATH_NOT_FOUND))
            {
                mmi_ucs2cpy((PS8) g_phnset_screensaver_default_file_1.filename, (PS8)L"");
            }
        }

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_048, ss_fh);
    }
    
    if ((g_phnset_screensaver_default_file_2.is_short == 0)
        && (mmi_ucs2cmp((PS8) g_phnset_screensaver_default_file_2.filename, (PS8)L"") != 0))
    {
        FS_HANDLE ss_fh;
        
        ss_fh = FS_Open((const unsigned short *)  g_phnset_screensaver_default_file_2.filename, FS_READ_ONLY);
        
        if (ss_fh >= 0)
        {
            S32 temp_int2;
            
            FS_Close(ss_fh);
            
            temp_int2 = mmi_phnset_del_file((const unsigned short *)  g_phnset_screensaver_default_file_2.filename);

            if (temp_int2 >= FS_NO_ERROR)
            {
                mmi_ucs2cpy((PS8) g_phnset_screensaver_default_file_2.filename, (PS8)L"");
            }

            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_046, temp_int2);
        }
        else
        {
            if ((ss_fh == FS_FILE_NOT_FOUND) || (ss_fh == FS_PATH_NOT_FOUND))
            {
                mmi_ucs2cpy((PS8) g_phnset_screensaver_default_file_2.filename, (PS8)L"");
            }
        }

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_049, ss_fh);
    }
}


/*****************************************************************************
* FUNCTION
*  mmi_phnset_init_default_file
* DESCRIPTION
*  
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_phnset_init_default_file(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/	
    S16 drive;
    s8 path_ascii[64];
    S8 path[64 * 2];
    FS_HANDLE fh;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    drive = SRV_FMGR_PUBLIC_DRV;
    if (drive > 0)
    {
        /* Create Path */
        memset(path_ascii, 0x00, 64);
        sprintf(path_ascii, "%c:\\%s", (S8)drive, FMGR_DEFAULT_FOLDER_SETTINGS);
        mmi_asc_to_ucs2(path, path_ascii);
        
        fh = FS_Open((U16*) path, FS_OPEN_DIR | FS_READ_ONLY);
        
        /* Folder Exists */
        if (fh > 0)
        {
            FS_SetAttributes((U16*) path, FS_ATTR_DIR | FS_ATTR_HIDDEN);
            FS_Close(fh);

            sprintf((PS8)PHNSET_DEFAULT_WP_PATH_1, "%c:\\%s", (S8)drive, PHNSET_DEFAULT_WP_PATH_1_path);
            sprintf((PS8)PHNSET_DEFAULT_WP_PATH_2, "%c:\\%s", (S8)drive, PHNSET_DEFAULT_WP_PATH_2_path);
            sprintf((PS8)PHNSET_DEFAULT_SS_PATH_1, "%c:\\%s", (S8)drive, PHNSET_DEFAULT_SS_PATH_1_path);
            sprintf((PS8)PHNSET_DEFAULT_SS_PATH_2, "%c:\\%s", (S8)drive, PHNSET_DEFAULT_SS_PATH_2_path);
        }
    }

}


/*****************************************************************************
* FUNCTION
*  mmi_phnset_init_folder
* DESCRIPTION
*  
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_phnset_init_folder(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/	
    S16 drive;
    S16 error;
    S32 result = FS_NO_ERROR;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_050);

    ReadRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 3, &g_phnset_wallpaper_default_file_1, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);
    ReadRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 4, &g_phnset_wallpaper_default_file_2, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);    
    ReadRecord(NVRAM_EF_SCREENSAVER_FILENAME_LID, 2, &g_phnset_screensaver_default_file_1, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);    
    ReadRecord(NVRAM_EF_SCREENSAVER_FILENAME_LID, 3, &g_phnset_screensaver_default_file_2, sizeof(mmi_phnset_wp_ss_pwrdisp_common_filename_struct), &error);        
//    ReadRecord(NVRAM_EF_WPSS_FILENAME_LID, 5, &phnset_wpss_default_file_2, sizeof(phnset_wpss_default_file_2), &error);

    FS_CreateDir(PHNSET_PREDEFINED_WP_PATH);    

    /* Make a copy of the selected file to setting folder. */
    drive = SRV_FMGR_PUBLIC_DRV;
    if (drive > 0)
    {
        /* Create Path */
#if 0        
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
        mmi_phnset_wallpaper_prepare_folder(drive);
        /* init default file name and path */
        mmi_phnset_init_default_file();

        /* init default wallpaper & screen saver file name and save in global structure */
        mmi_phnset_del_dirty_file();
            
        /* get postfix of copied file in default folder and set to idle wallpaper */
        {
            FS_HANDLE fh2; 
            U8 path_ucs2[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
            
            if ( g_phnset_wallpaper_default_file_1.is_short == 1)
            {
                mmi_ucs2cpy((PS8)path_ucs2, (PS8)g_phnset_wallpaper_default_file_1.filename);
            }
            else if ( g_phnset_wallpaper_default_file_2.is_short == 1)
            {
                mmi_ucs2cpy((PS8)path_ucs2, (PS8)g_phnset_wallpaper_default_file_2.filename);
            }
            
            fh2 = FS_Open((const unsigned short *) path_ucs2, FS_READ_ONLY);
            
            if(fh2 >= 0)
            {
                FS_Close(fh2);
                mmi_ucs2cpy((PS8)phnset_wp_default_file, (PS8)path_ucs2);
                idle_screen_wallpaper_name = (PS8)phnset_wp_default_file;
                idle_screen_wallpaper_name_original = (PS8)phnset_wp_default_file;
            }
            else /* copy wallpaper to default folder */
            {
                MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_052);
            }
        }

        /* init default screen saver file name and save in global structure */
        {
            FS_HANDLE ss_fh;
            U8 path_ucs2[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
            
            if ( g_phnset_screensaver_default_file_1.is_short == 1)
            {
                mmi_ucs2cpy((PS8)path_ucs2, (PS8) g_phnset_screensaver_default_file_1.filename);
            }
            else if ( g_phnset_screensaver_default_file_2.is_short == 1)
            {
                mmi_ucs2cpy((PS8)path_ucs2, (PS8) g_phnset_screensaver_default_file_2.filename);
            }

            ss_fh = FS_Open((const unsigned short *) path_ucs2, FS_READ_ONLY | FS_NOBUSY_CHECK_MODE);
            
            if (ss_fh >= 0)
            {                
                FS_Close(ss_fh);
                mmi_ucs2cpy((PS8)phnset_ss_default_file, (PS8) path_ucs2);
                idle_screen_screensaver_name = (PS8)phnset_ss_default_file;
            }
        }
    }
}
/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_check_file_limit
 * DESCRIPTION
 *  Check file before display 
 * PARAMETERS
 *  
 * RETURNS
 *  U8
 *****************************************************************************/
static U8 mmi_phnset_check_file_limit(U8* filename)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!filename)
	{
	    return MMI_FALSE; //Null file name
	}
    if ((g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP
         && !mmi_fmgr_util_file_limit_check(FMGR_LIMIT_WALLPAPER, (PS8) filename, &error_str_ptr))
#ifdef __MMI_SUB_WALLPAPER__
        || (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP
            && !mmi_fmgr_util_file_limit_check(FMGR_LIMIT_SUB_WALLPAPER, (PS8) filename, &error_str_ptr))
#endif /* __MMI_SUB_WALLPAPER__ */ 
        || (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS
            && !mmi_fmgr_util_file_limit_check(FMGR_LIMIT_SCREEN_SAVER, (PS8) filename, &error_str_ptr)))
    {
        PhnsetWpUsrDefFreeBuf();
        return PHNSET_WP_SS_SET_FILE_LIMIT_CHECK_FAIL;
    }
    return PHNSET_WP_SS_SET_NO_ERROR;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_init_filename
 * DESCRIPTION
 *  Copy filename to global variable 
 * PARAMETERS
 *  
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
static U8 mmi_phnset_wallpaper_init_filename(PS8 filename, S32 is_short)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* Prevent memory leck, after buffer is free, set pointer to NULL */
    ASSERT(phnset_dispchar_strp == NULL);
    
    g_phnset_cntx_p->isShort = is_short;    

    phnset_dispchar_strp = OslMalloc(SRV_FMGR_PATH_BUFFER_SIZE);
    if (phnset_dispchar_strp)
    {
        mmi_ucs2cpy((S8*) phnset_dispchar_strp, (S8*) filename);
    }
    else
    {
        return PHNSET_WP_SS_SET_FILE_NAME_BUF_ALLOC_FAIL;
    }
    return PHNSET_WP_SS_SET_NO_ERROR;
}
 

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_prepare_folder
 * DESCRIPTION
 *  Check Settings directory is available, create directory if it can not be found 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static U8 mmi_phnset_wallpaper_prepare_folder(S16 driver)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    FS_HANDLE fh;
    U32 new_file_len = 0;   /* size of new file */
    s8 path_ascii[64];
    S8 path[64 * 2];
    S32 result = FS_NO_ERROR; 
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (driver > 0)
    {
        /* Create Path */
        memset(path_ascii, 0x00, 64);
        sprintf(path_ascii, "%c:\\%s", (S8)driver, FMGR_DEFAULT_FOLDER_SETTINGS);
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_023, path_ascii);
        mmi_asc_to_ucs2(path, path_ascii);
        
        fh = FS_Open((U16*) path, FS_OPEN_DIR | FS_READ_ONLY);
        
        /* Folder Exists */
        if (fh > 0)
        {
            FS_SetAttributes((U16*) path, FS_ATTR_DIR | FS_ATTR_HIDDEN);
            FS_Close(fh);
        }
        /* Folder Does Not Exist */
        else
        {
            result = FS_CreateDir((U16*) path);
            /* Create Success */
            if (result == FS_NO_ERROR)
            {
                FS_SetAttributes((U16*) path, FS_ATTR_DIR | FS_ATTR_HIDDEN);
            }
            else
            {
                MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_024, result);
                return PHNSET_WP_SS_SET_PREPARE_FOLDER_FAIL;
            }
        }
    } 
    else
    {
        return PHNSET_WP_SS_SET_PREPARE_FOLDER_FAIL;
    }
    return PHNSET_WP_SS_SET_NO_ERROR;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_check_disk
 * DESCRIPTION
 *  Check disk space and prepare for file copy 
 * PARAMETERS
 *  
 * RETURNS
 *  static U8
 *****************************************************************************/
static U8 mmi_phnset_wallpaper_check_disk(S16 driver)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    FS_HANDLE fh;
    FS_DiskInfo disk_info;    
    U32 new_file_len = 0;   /* size of new file */
    U64 disk_free_space;
    U64 disk_total_space;
    S8 file_path_ascii[5];
    S8 file_path_ascii_2[5] = ":\\";
    S8 file_path[10];    
    S32 fs_ret;        
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* open current file and get file size */
    fh = FS_Open((const unsigned short *) phnset_dispchar_strp, FS_READ_ONLY);

    if(fh >= 0)
    {
        FS_GetFileSize(fh, &new_file_len);
        FS_Close(fh);

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_025, new_file_len);
        if(new_file_len == 0)
        {
            mmi_phnset_del_file((const unsigned short *) phnset_dispchar_strp);
        }
    }

    /* check device status */
    disk_free_space = 0;
    disk_total_space = 0;
    sprintf(file_path_ascii, "%c%s", driver, file_path_ascii_2);
    mmi_asc_to_ucs2((PS8)file_path, file_path_ascii);
    
    fs_ret = FS_GetDiskInfo((PU16) file_path, &disk_info, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);

    if (fs_ret >= 0)
    {
        disk_free_space = disk_info.FreeClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
        disk_total_space = disk_info.TotalClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_026, disk_free_space);
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_027, disk_total_space);
        if (new_file_len >= disk_free_space)
        {
            return PHNSET_WP_SS_SET_DISK_SIZE_NOT_ENOUGH;
        }
    }
    else
    {
        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_028);
        return PHNSET_WP_SS_SET_GET_DISK_INFO_FAIL;
    }    

    return PHNSET_WP_SS_SET_NO_ERROR;    
}
 

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_prepare_file_path
 * DESCRIPTION
 *  Prepare file path global variable 
 * PARAMETERS
 *  
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
static U8 mmi_phnset_wallpaper_prepare_file_path(U8 *user_file_path)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 path_asc[SRV_FMGR_PATH_MAX_LEN + 1];
    U8 postfix[SRV_FMGR_PATH_MAX_FILE_EXT_LEN];
    U8 path_ucs2[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
    FS_HANDLE fh;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
 
    mmi_phnset_get_postfix_ucs2((PU8) postfix, (PU8) phnset_dispchar_strp);
    
    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        memset(phnset_dispchar_wp_cp_file, 0x00, ((SRV_FMGR_PATH_MAX_LEN + 1) * 2));

        /* default file 1 is empty */
        if ((g_phnset_wallpaper_default_file_1.is_short == 0) 
            && (mmi_ucs2cmp((PS8)g_phnset_wallpaper_default_file_1.filename, (PS8)L"") == 0))
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_030);
            g_phnset_wallpaper_default_file_1.is_short= 1;
            sprintf((PS8) path_asc, "%s.%s", PHNSET_DEFAULT_WP_PATH_1, postfix);
        }
        else if ((g_phnset_wallpaper_default_file_2.is_short == 0)
            && (mmi_ucs2cmp((PS8)g_phnset_wallpaper_default_file_2.filename, (PS8)L"") == 0))
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_031);
            g_phnset_wallpaper_default_file_2.is_short= 1;
            sprintf((PS8) path_asc, "%s.%s", PHNSET_DEFAULT_WP_PATH_2, postfix);
        }

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_032, path_asc);
        mmi_asc_to_ucs2((PS8) path_ucs2, (PS8) path_asc);
        mmi_ucs2cpy((PS8) phnset_dispchar_wp_cp_file, (PS8) path_ucs2);
    }
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
    {
        memset(phnset_dispchar_ss_cp_file, 0x00, ((SRV_FMGR_PATH_MAX_LEN + 1) * 2));

        /* default file 1 is in use */
        if ((g_phnset_screensaver_default_file_1.is_short == 0)
            && (mmi_ucs2cmp((PS8)g_phnset_screensaver_default_file_1.filename, (PS8)L"") == 0))
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_033);
            g_phnset_screensaver_default_file_1.is_short= 1;
            sprintf((PS8) path_asc, "%s.%s", PHNSET_DEFAULT_SS_PATH_1, postfix);
        }
        else if ((g_phnset_screensaver_default_file_2.is_short== 0)
            && (mmi_ucs2cmp((PS8)g_phnset_screensaver_default_file_2.filename, (PS8)L"") == 0))
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_034);
            g_phnset_screensaver_default_file_2.is_short = 1;
            sprintf((PS8) path_asc, "%s.%s", PHNSET_DEFAULT_SS_PATH_2, postfix);
        }

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_035, path_asc);
        mmi_asc_to_ucs2((PS8) path_ucs2, (PS8) path_asc);
        mmi_ucs2cpy((PS8) phnset_dispchar_ss_cp_file, (PS8) path_ucs2);
    }

    /* delete exist file with same name */
    fh = FS_Open((U16 *)path_ucs2, FS_READ_ONLY);

    if (fh >= FS_NO_ERROR)
    {
        S32 ret_del;

        FS_Close(fh);
        ret_del = mmi_phnset_del_file((const unsigned short *)path_ucs2);

        MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_036, ret_del);
    }
    else
    {
        if ((fh != FS_FILE_NOT_FOUND) && (fh != FS_PATH_NOT_FOUND))
        {
            MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_037, fh);
            return PHNSET_WP_SS_SET_PREPARE_FILE_FAIL;
        }
    }
    memcpy(
        user_file_path,
        path_ucs2,
        ((SRV_FMGR_PATH_MAX_LEN + 1) * 2));
    
    return PHNSET_WP_SS_SET_NO_ERROR;
}
 

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wp_ss_set_by_filename
 * DESCRIPTION
 *  Internal function for set wallpaper and screensaver by filename
 * PARAMETERS
 *  filename
 *  callback
 * RETURNS
 *  error code
 *****************************************************************************/
static U8 mmi_phnset_wp_ss_set_by_filename(WCHAR* filename, phnset_wp_ss_funcptr callback, void *userdata)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 process_result;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ASSERT(filename);

    if (app_ucs2_strlen(filename) > (SRV_FMGR_PATH_MAX_LEN + 1))
    {
        ASSERT(0);        
    }

    g_phnset_wp_ss_set_callback = callback; 
    g_phnset_wp_ss_set_userdata = userdata;
    
#if 0    
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif

    process_result = mmi_phnset_wallpaper_init_filename((PS8)filename, 1);
    ASSERT(process_result == PHNSET_WP_SS_SET_NO_ERROR);
    
    process_result = mmi_phnset_copy_wallpaper_screensaver();
    if (process_result != PHNSET_WP_SS_SET_NO_ERROR)
	{
        /* file name buffer can not allocate */
        mmi_phnset_wp_ss_restore_para();
        PhnsetWpUsrDefFreeBuf();
	    return process_result;
	}
    
    return PHNSET_WP_SS_SET_NO_ERROR;  
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wp_ss_get_error_str_id
 * DESCRIPTION
 *  Get set wallpaper error code related string id 
 * PARAMETERS
 *  error_code  [IN]
 * RETURNS
 *  U16
 *****************************************************************************/
static U16 mmi_phnset_wp_ss_get_error_str_id(U16 error_code)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (error_code)
	{
	case PHNSET_WP_SS_SET_NO_ERROR:
        return STR_GLOBAL_DONE;
        
    case PHNSET_WP_SS_SET_NOT_AVAILABLE:
        return STR_GLOBAL_NOT_AVAILABLE;
        
    case PHNSET_WP_SS_SET_DISK_SIZE_NOT_ENOUGH:
        return FMGR_FS_DISK_FULL_TEXT;
        
	case PHNSET_WP_SS_SET_COPY_FILE_FAIL:
        return (U16)file_copy_result_str_id;
		
	default:
		ASSERT(0);
        break;
	}
    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_set_wallpaper_by_filename
 * DESCRIPTION
 *  External API for set wallpaper. Input filepath will be copy to wallpaper 
 *  global variable. Wallpaper file will be copied to system directory, if any 
 *  error occurr before copy, this function will retrun an error code. Copy 
 *  result will be send in callback fuction.
 * PARAMETERS
 *  filename    [IN] file path and file name string in UCS2
 *  callback    [IN] void callback(U8 set_result)
 * RETURNS
 *  U8  return 0 if pre-check is correct, else return error code
 *****************************************************************************/
U8 mmi_phnset_wallpaper_set_by_filename(WCHAR* filename, phnset_wp_ss_funcptr callback, void* userdata)
{
    if (phnset_dispchar_strp || g_phnset_wp_ss_set_callback || g_wpss_type_backup)
	{
        return PHNSET_WP_SS_SET_NOT_AVAILABLE;
	}
    mmi_phnset_wp_ss_backup_para(); 
    g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP;
    return mmi_phnset_wp_ss_set_by_filename(filename, callback, userdata);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_get_wallpaper_set_error_str_id
 * DESCRIPTION
 *  Get set wallpaper error code related string id 
 * PARAMETERS
 *  
 * RETURNS
 *  U16
 *****************************************************************************/
U16 mmi_phnset_wallpaper_get_error_str_id(U16 error_code)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return mmi_phnset_wp_ss_get_error_str_id(error_code);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_screensaver_set_by_filename
 * DESCRIPTION
 *  External API for set screensaver. Input filepath will be copy to wallpaper 
 *  global variable. Wallpaper file will be copied to system directory, if any 
 *  error occurr before copy, this function will retrun an error code. Copy 
 *  result will be send in callback fuction.
 * PARAMETERS
 *  filename    [IN] file path and file name string in UCS2
 *  callback    [IN] void callback(U8 set_result)
 *  userdata    [IN] the userdata will be send to callback function
 * RETURNS
 *  U8  return 0 if pre-check is correct, else return error code
 *****************************************************************************/
U8 mmi_phnset_screensaver_set_by_filename(WCHAR* filename, phnset_wp_ss_funcptr callback, void* userdata)
{
    if (phnset_dispchar_strp || g_phnset_wp_ss_set_callback || g_wpss_type_backup)
	{
        return PHNSET_WP_SS_SET_NOT_AVAILABLE;
	}
    mmi_phnset_wp_ss_backup_para();   
    g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_SS;
    return mmi_phnset_wp_ss_set_by_filename(filename, callback, userdata);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_screensaver_get_error_str_id
 * DESCRIPTION
 *  Get set wallpaper error code related string id 
 * PARAMETERS
 *  
 * RETURNS
 *  U16
 *****************************************************************************/
U16 mmi_phnset_screensaver_get_error_str_id(U16 error_code)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return mmi_phnset_wp_ss_get_error_str_id(error_code);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wp_ss_backup_para
 * DESCRIPTION
 *  Backup wallpaper and screensaver set parameter  
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_wp_ss_backup_para(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phnset_cntx_p->wpss_type)
	{
	    g_wpss_type_backup = g_phnset_cntx_p->wpss_type;
	}      
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wp_ss_restore_para
 * DESCRIPTION
 *  Restore wallpaper and screensaver set paramters from backup 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_wp_ss_restore_para(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_wpss_type_backup)
	{
	    g_phnset_cntx_p->wpss_type = g_wpss_type_backup;
        g_wpss_type_backup = MMI_PHNSET_TYPE_AVAILABLE;
	}
    g_phnset_wp_ss_set_callback = NULL;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_display_fmgr_common_proc
 * DESCRIPTION
 *  Proc function for file manager cui used in wallpaper screen saver and power
 *  on off display 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_display_fmgr_common_proc(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    //FMGR_FILE_INFO_STRUCT file_info;
    srv_fmgr_fileinfo_struct file_info;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->evt_id)
    {
    case EVT_ID_GROUP_DEINIT:
    case EVT_ID_GROUP_DELETE_REQ:
    case EVT_ID_GROUP_DELETE_REQ_IN_END_KEY:        
        PhnsetWpUsrDefFreeBuf();
        if (file_path_buf)
    	{
            OslMfree(file_path_buf);
            file_path_buf = NULL;
    	}        
    	break;
    case EVT_ID_CUI_FILE_SELECTOR_RESULT:
        if (((cui_file_selector_result_event_struct*)param)->result <= 0)
    	{
            if (file_path_buf)
        	{
                OslMfree(file_path_buf);
                file_path_buf = NULL;
        	}
    	    cui_file_selector_close(mmi_frm_group_get_active_id());
    	}
        else
        {
            file_path_buf = (PU8)OslMalloc((SRV_FMGR_PATH_MAX_LEN + 1) * 2);
            
            cui_file_selector_get_selected_filepath(
                mmi_frm_group_get_active_id(),
                &file_info,
                (WCHAR*)file_path_buf,
                (SRV_FMGR_PATH_MAX_LEN + 1) * 2);
#ifdef __MMI_POWER_ON_OFF_DISPLAY__            
            if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_PWRON || g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_PWROFF)
        	{
        	    PhnsetPwrOnOffSelectFmgrCallBack((void*)file_path_buf, (ENCODING_LENGTH - 1));
        	}
            else
#endif                
            {
                PhnsetWallpaperSelectFmgrCallBack((void*)file_path_buf, (ENCODING_LENGTH - 1));
            }
	    if (file_path_buf)
    	    {
		OslMfree(file_path_buf);
		file_path_buf = NULL;
            } 
        }
    default:
        break;    	
    }
    return MMI_RET_OK;    
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_set_file_filter
 * DESCRIPTION
 *  Set file filter for wallpaper, screen saver, power on/off  display. 
 * PARAMETERS
 *  
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_display_set_file_filter(FMGR_FILTER *filter, phnset_wpss_type_enum type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* Check capability of SUB LCD */
#ifdef __MMI_SUB_WALLPAPER__
    if (type == MMI_PHNSET_TYPE_SUB_WP)
	{
        U32 img_flag = 0;
        mmi_phnset_display_set_file_filter_by_struct(filter, mmi_phnset_display_support_sub_image_type);
    #ifdef JPG_DECODE

        gdi_capability_decoder_concurrency(GDI_IMAGE_TYPE_JPG, &img_flag);

        if (img_flag | GDI_CAPABILITY_NO_VIDEO == GDI_CAPABILITY_NO_VIDEO)
        {
            FMGR_FILTER_CLEAR(filter, FMGR_TYPE_JPG);
            FMGR_FILTER_CLEAR(filter, FMGR_TYPE_JPEG);
        }
    #endif /* JPG_DECODE */	
        return;
	}
#endif 		

    /* Set filter for video file */    
    switch (type)
	{
    case MMI_PHNSET_TYPE_SS:
#if defined(__MMI_SCREENSAVER_DISPLAY_VIDEO__)        
        mmi_phnset_display_set_file_filter_by_struct(filter, mmi_phnset_display_support_video_type);
#endif
        break;

#ifdef __MMI_POWER_ON_OFF_DISPLAY__
    case MMI_PHNSET_TYPE_PWRON:
    case MMI_PHNSET_TYPE_PWROFF:
#if defined(__MMI_POWER_ON_OFF_DISPLAY_VIDEO__)
        mmi_phnset_display_set_file_filter_by_struct(filter, mmi_phnset_display_support_video_type);
#endif
        break;        
#endif /* __MMI_POWER_ON_OFF_DISPLAY__ */ 

	default:
		break;
	}

    /* Set filter for image file */
    mmi_phnset_display_set_file_filter_by_struct(filter, mmi_phnset_display_support_image_type);    
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_disp_set_file_filter_from_support_struct
 * DESCRIPTION
 *  Set file filter from structure 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_display_set_file_filter_by_struct(FMGR_FILTER *filter, mmi_phnset_display_file_type_struct *filter_struct)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 i;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!filter || !filter_struct)
	{
	    return;
	}
    for (i = 0; filter_struct[i].support_type != FMGR_TYPE_UNKNOWN; i++)
	{
        FMGR_FILTER_SET(filter, filter_struct[i].support_type); 		
	}
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_display_check_file_type
 * DESCRIPTION
 *  Check if the input file type is supported 
 * PARAMETERS
 *  
 * RETURNS
 *  MMI_BOOL
 *****************************************************************************/
MMI_BOOL mmi_phnset_display_check_file_type(U16 file_type, phnset_wpss_type_enum type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MMI_BOOL result = MMI_FALSE;
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __MMI_SUB_WALLPAPER__
    if (type == MMI_PHNSET_TYPE_SUB_WP)
	{
        U32 img_flag = 0;
        result = mmi_phnset_display_is_file_type_in_struct(file_type, mmi_phnset_display_support_sub_image_type);
    #ifdef JPG_DECODE

        gdi_capability_decoder_concurrency(GDI_IMAGE_TYPE_JPG, &img_flag);

        if (img_flag | GDI_CAPABILITY_NO_VIDEO == GDI_CAPABILITY_NO_VIDEO)
        {
            if ((file_type == FMGR_TYPE_JPG) || (file_type == FMGR_TYPE_JPEG))
        	{
        	    return MMI_FALSE;
        	}
        }
    #endif /* JPG_DECODE */	
        return result;
	}
#endif 	    

    switch (type)
	{
	case MMI_PHNSET_TYPE_SS:
#if defined(__MMI_SCREENSAVER_DISPLAY_VIDEO__)
        result = mmi_phnset_display_is_file_type_in_struct(file_type, mmi_phnset_display_support_video_type);
#endif
        break;     

#ifdef __MMI_POWER_ON_OFF_DISPLAY__
    case MMI_PHNSET_TYPE_PWRON:
    case MMI_PHNSET_TYPE_PWROFF:
#if defined(__MMI_POWER_ON_OFF_DISPLAY_VIDEO__)
        result = mmi_phnset_display_is_file_type_in_struct(file_type, mmi_phnset_display_support_video_type);
#endif
    	break;
#endif /* __MMI_POWER_ON_OFF_DISPLAY__ */ 

	default:
		break;
	}
    if (result)
	{
	    return result;
	}
    result = mmi_phnset_display_is_file_type_in_struct(file_type, mmi_phnset_display_support_image_type);
    return result;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_display_is_file_type_support_in_struct
 * DESCRIPTION
 *  Check if this file type is in the input structure 
 * PARAMETERS
 *  
 * RETURNS
 *  static MMI_BOOL
 *****************************************************************************/
static MMI_BOOL mmi_phnset_display_is_file_type_in_struct(U16 file_type, mmi_phnset_display_file_type_struct *filter_struct)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 i;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!filter_struct)
	{
	    return;
	}
    for (i = 0; filter_struct[i].support_type != FMGR_TYPE_UNKNOWN; i++)
	{
        if (file_type == filter_struct[i].support_type)		
    	{
    	    return MMI_TRUE;
    	}
	}
    return MMI_FALSE;
}

#endif /* __MMI_FILE_MANAGER__ */


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_preview_proc
 * DESCRIPTION
 *  Proc function for wallpaper group 
 * PARAMETERS
 *  param   [IN]
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_preview_proc(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->evt_id)
    {
    case EVT_ID_GROUP_DEINIT:
    case EVT_ID_GROUP_DELETE_REQ:
    case EVT_ID_GROUP_DELETE_REQ_IN_END_KEY:        
        PhnsetWpUsrDefFreeBuf();
    	break;

    default:
        break;    	
    }
    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_menu_proc
 * DESCRIPTION
 *  Proc function for wallpaper menu CUI 
 * PARAMETERS
 *  param   [IN]
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
mmi_ret mmi_phnset_wallpaper_sub_menu_handler(cui_menu_event_struct *param, MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->evt_id)
    {
    case EVT_ID_CUI_MENU_LIST_ENTRY:
        return mmi_phnset_wallpaper_sub_menu_entry_handler(param, parent_gid);

    case EVT_ID_CUI_MENU_ITEM_HILITE:
        return mmi_phnset_wallpaper_sub_menu_highlight_handler(param, parent_gid);

    case EVT_ID_CUI_MENU_ITEM_SELECT:
    case EVT_ID_CUI_MENU_ITEM_TAP:
        return mmi_phnset_wallpaper_sub_menu_select_handler(param, parent_gid);
       
    default:
        break;            
    }		

    return MMI_RET_DONT_CARE;
}



/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_sub_menu_entry_handler
 * DESCRIPTION
 *  Entry proc function for wallpaper menu cui 
 * PARAMETERS
 *  param   [IN]
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_sub_menu_entry_handler(cui_menu_event_struct *param, MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    switch (param->parent_menu_id)
    {
    case MENU_SETTING_WALLPAPER:
#if defined(__DAILY_WALLPAPER__) && defined(__MMI_FILE_MANAGER__)
    case MENU_SETTING_WALLPAPER_FIX:        
#endif        
#ifdef __MMI_SUB_WALLPAPER__
    case MENU_SETTING_WALLPAPER_SUB:
#endif        
    	mmi_phnset_init_wallpaper_menu();
        return MMI_RET_OK;
    	break;
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER__        
    case MENU_SETTING_WALLPAPER_GALLERY:
        cui_menu_set_currlist_flags(param->sender_id, CUI_MENU_NORMAL_LIST_WITH_NUMBERED_ICONS);        
        cui_menu_set_currlist_title(param->sender_id, (WCHAR*)GetString(STR_ID_WALLPAPER_GALLERY), (U8*)GetImage(IMG_SCR_SETTING_CAPTION));
        return MMI_RET_OK;
    	break;
#endif

    default:
    	break;
    }
    return MMI_RET_DONT_CARE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_sub_menu_highlight_handler
 * DESCRIPTION
 *  Highlight proc function for wallpaper menu cui
 * PARAMETERS
 *  param   [IN]
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_sub_menu_highlight_handler(cui_menu_event_struct *param, MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 lsk_str_id;
    U8 lsk_status; /* 0 -- ON, 1 -- OFF */  
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->highlighted_menu_id)
    {
    default:
        return MMI_RET_DONT_CARE;
    }
    lsk_str_id = lsk_status == 0 ? STR_GLOBAL_ON : STR_GLOBAL_OFF;    
    cui_menu_change_left_softkey_string(mmi_frm_group_get_active_id(), (WCHAR*)GetString(lsk_str_id));	
    return MMI_RET_OK;    
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_sub_menu_select_handler
 * DESCRIPTION
 *  select proc function for wallpaper menu cui
 * PARAMETERS
 *  param   [IN]
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_sub_menu_select_handler(cui_menu_event_struct *param, MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->highlighted_menu_id)
    {
/* Main menu of wallpaper setting */        
    case MENU_SETTING_WALLPAPER:
        g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP;
#if !defined(__MMI_FILE_MANAGER__) && !defined(__DAILY_WALLPAPER__)
        EntryPhnsetWallpaperSys(parent_gid);
        return MMI_RET_OK;        
#endif
        mmi_phnset_wallpaper_entry_main(parent_gid);
        return MMI_RET_OK;
        break;
        
#ifdef __MMI_SUB_WALLPAPER__
    case MENU_SETTING_WALLPAPER_SUB:
        g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_SUB_WP;
#if !defined(__MMI_FILE_MANAGER__) && !defined(__DAILY_WALLPAPER__)
        EntryPhnsetWallpaperSys(parent_gid);
        return MMI_RET_OK;        
#endif
        mmi_phnset_wallpaper_entry_main(parent_gid);
        return MMI_RET_OK;
        break;
#endif


/* Sub menu of wallpaper setting */        
#ifdef __MMI_FILE_MANAGER__
    case MENU_SETTING_WALLPAPER_DOWNLOAD:
        EntryPhnsetWallpaperFmgr(parent_gid);
        return MMI_RET_OK;        
#endif /* __MMI_FILE_MANAGER__ */

    case MENU_SETTING_WALLPAPER_SYSTEM:
        EntryPhnsetWallpaperSys(parent_gid);
        return MMI_RET_OK;        
      
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER__
    case MENU_SETTING_LIVE_WALLPAPER:
        mmi_phnset_wallpaper_entry_vui_live_wallpaper(parent_gid);
        return MMI_RET_OK;
#endif

/* Old feature, may phase out */
#ifdef __DAILY_WALLPAPER__        
#if !defined(__MMI_FILE_MANAGER__)
    case MENU_SETTING_WALLPAPER_FIX:
        EntryPhnsetWallpaperSys(parent_gid);
        return MMI_RET_OK;
#endif /* !defined(__MMI_FILE_MANAGER__) */

    case MENU_SETTING_WALLPAPER_ROTATE:
        mmi_phnset_entry_wallpaper_rotate(parent_gid);
        return MMI_RET_OK;        
#endif /* __DAILY_WALLPAPER__ */        
        
#ifdef __MMI_AVATAR__
    case MENU_ID_PHNSET_WP_AVATAR:
        mmi_phnset_avatar_entry();
        return MMI_RET_OK;        
#endif
        
    default:
        break;
    }
    return MMI_RET_DONT_CARE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_init_wallpaper_menu
 * DESCRIPTION
 *  Initialize the wallpaper menu 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phnset_init_wallpaper_menu(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MMI_ID wallpaper_menu_cui_id = mmi_frm_group_get_active_id();
    U16 title_str_id;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* set menu list flags to numbered icon menu list at the first time enter*/
    cui_menu_set_currlist_flags(wallpaper_menu_cui_id, CUI_MENU_NORMAL_LIST_WITH_NUMBERED_ICONS);

    /* set title */
    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
	{
#ifdef __DAILY_WALLPAPER__
	    title_str_id = STR_WALLPAPER_CAPTION;
#else
	    title_str_id = STR_SETTING_WALLPAPER;
#endif
	}
#ifdef __MMI_SUB_WALLPAPER__
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SUB_WP)
	{
	    title_str_id = STR_SETTING_WALLPAPER_SUB;
	}
#endif
    cui_menu_set_currlist_title(wallpaper_menu_cui_id, (WCHAR*)GetString(title_str_id), (U8*)GetImage(IMG_SCR_SETTING_CAPTION));
    cui_menu_set_currlist_left_softkey(wallpaper_menu_cui_id, (WCHAR*)GetString(STR_GLOBAL_OK));
    cui_menu_set_currlist_right_softkey(wallpaper_menu_cui_id, (WCHAR*)GetString(STR_GLOBAL_BACK)); 
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_entry_main
 * DESCRIPTION
 *  Main menu of wallpaer 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_wallpaper_entry_main(mmi_id parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_id menucui_gid;
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_MAIN))
	{
	    mmi_popup_display_simple((WCHAR*)GetString(STR_GLOBAL_NOT_AVAILABLE), MMI_EVENT_NOT_AVAILABLE, GRP_ID_ROOT, NULL);
        return;
	}
    if (!parent_gid)
	{
	    parent_gid = GRP_ID_ROOT;
	}

    mmi_frm_group_create(
        parent_gid,
        GRP_ID_WALLPAPER_MAIN,
        mmi_phnset_wallpaper_main_menu_proc,
        NULL);

    mmi_frm_group_enter(GRP_ID_WALLPAPER_MAIN, MMI_FRM_NODE_SMART_CLOSE_FLAG);

    menucui_gid = cui_menu_create(
        GRP_ID_WALLPAPER_MAIN,
        CUI_MENU_SRC_TYPE_RESOURCE,
        CUI_MENU_TYPE_APPMAIN,
        MENU_SETTING_WALLPAPER,
        MMI_FALSE,
        NULL);
    
    cui_menu_run(menucui_gid);
    
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_main_menu_proc
 * DESCRIPTION
 *  Proc function of wallpaper setting main menu 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_main_menu_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (evt->evt_id == EVT_ID_CUI_MENU_CLOSE_REQUEST)
	{
	    cui_menu_close(((cui_menu_event_struct*)evt)->sender_id);
        return MMI_RET_OK;
	}
    else if (cui_menu_is_menu_event(evt->evt_id))
    {        
        return mmi_phnset_wallpaper_sub_menu_handler((cui_menu_event_struct*)evt,GRP_ID_WALLPAPER_MAIN);
    }    
    return MMI_RET_OK;
}
 

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_entry_system
 * DESCRIPTION
 *  Entry system resource list screen of wallpaper, for external used. 
 * PARAMETERS
 *  parent_gid  :   [IN]    Group ID of parent
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_wallpaper_entry_system(MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP;
    EntryPhnsetWallpaperSys(parent_gid);
}

#ifdef __MMI_VUI_HOMESCREEN__
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER__
/*
 *  Live wallpaper
 */ 
/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_entry_vui_live_wallpaper
 * DESCRIPTION
 *  Entry live wallpaper setting menu 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
void mmi_phnset_wallpaper_entry_vui_live_wallpaper(mmi_id parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phnset_appcreate_menucui_create(parent_gid, GRP_ID_WALLPAPER_LIVE_WALLPAPER, MENU_SETTING_LIVE_WALLPAPER, mmi_phnset_wallpaper_live_wallpaper_proc);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_live_wallpaper_proc
 * DESCRIPTION
 *  Proc function for live wallpapaer setting 
 * PARAMETERS
 *  
 * RETURNS
 *  static mmi_ret
 *****************************************************************************/
static mmi_ret mmi_phnset_wallpaper_live_wallpaper_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    cui_menu_event_struct *menucui_evt = (cui_menu_event_struct*)evt;
    U8 sel_idx;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (menucui_evt->evt_id)
	{
	case EVT_ID_CUI_MENU_LIST_ENTRY:
		mmi_phnset_wallpaper_init_live_wallpaper();
		break;
        
    case EVT_ID_CUI_MENU_ITEM_SELECT:
        /* The 0 enum will not be displayed */        
        sel_idx = menucui_evt->highlighted_menu_id + 1;
        if (mmi_phnset_wallpaper_set_vui_live_wallpaper_setting(sel_idx))
    	{
    	    mmi_popup_display_simple((WCHAR*)GetString(STR_GLOBAL_DONE), MMI_EVENT_SUCCESS, GRP_ID_ROOT, NULL);
            cui_menu_close(menucui_evt->sender_id);
            if (mmi_frm_group_is_present(GRP_ID_WALLPAPER_MAIN))
        	{
                mmi_frm_group_close(GRP_ID_WALLPAPER_MAIN);
        	}
    	}
        else
        {
    	    mmi_popup_display_simple((WCHAR*)GetString(STR_GLOBAL_UNFINISHED), MMI_EVENT_FAILURE, GRP_ID_ROOT, NULL);
        }
        break;
        
    case EVT_ID_CUI_MENU_CLOSE_REQUEST:
        cui_menu_close(menucui_evt->sender_id);
        break;
        
	default:
		break;
	}
    return MMI_RET_OK;
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_init_live_wallpaper
 * DESCRIPTION
 *  Init function for live wallpaper setting menu 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static void mmi_phnset_wallpaper_init_live_wallpaper(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    phnset_radio_button_menu_data_struct radio_button_menu;
    /* Will not display selection of VappHsWallpaperWide */
    U8 nNumofItem = VAPP_HS_WALLPAPER_LAST_ITEM - 1;
    U16 string_id[] = {
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_WAVE__        
        STR_ID_WALLPAPER_VUI_LIVE_WAVE, 
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_SPANGLE__
        STR_ID_WALLPAPER_VUI_LIVE_SPANGLEGOLD, 
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_CHIPSET__
        STR_ID_WALLPAPER_VUI_LIVE_CHIPSET,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_COMET__
        STR_ID_WALLPAPER_VUI_LIVE_COMET, 
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_SPACE__
        STR_ID_WALLPAPER_VUI_LIVE_SPACE, 
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_MATRIX__
        STR_ID_WALLPAPER_VUI_LIVE_MATRIX, 
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_WILDWORLD__
        STR_ID_WALLPAPER_VUI_LIVE_WILDWORLD,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_FIREFLY__        
        STR_ID_WALLPAPER_VUI_LIVE_FIREFLY,
#endif        
        STR_GLOBAL_NONE // Used for ending, will not be displayed.
        };
    U8 highlight_item;
        
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* The 0 enum will not be displayed */
    if (mmi_phnset_wallpaper_get_vui_live_wallpaper_setting() >= 1)
    {
	    highlight_item = mmi_phnset_wallpaper_get_vui_live_wallpaper_setting() - 1;
    }
    else
    {
        highlight_item = 0;
    }
    
    /* Retrieve no of child of menu item to be displayed */
    radio_button_menu.group_id = GRP_ID_WALLPAPER_LIVE_WALLPAPER;
    radio_button_menu.menu_title_str_id = STR_ID_WALLPAPER_LIVE_WALLPAPER;
    radio_button_menu.menu_icon_id = MAIN_MENU_TITLE_SETTINGS_ICON;
    radio_button_menu.menu_item_num = nNumofItem;
    radio_button_menu.menu_item_str_list = NULL;
    radio_button_menu.menu_item_str_id_list = string_id;
    radio_button_menu.highlighted_item_idx = highlight_item; 
    mmi_phnset_init_radio_button_menu(&radio_button_menu);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_set_vui_live_wallpaper_setting
 * DESCRIPTION
 *  Save Live wallpaper setting to NVRAM 
 * PARAMETERS
 *  
 * RETURNS
 *  static void
 *****************************************************************************/
static MMI_BOOL mmi_phnset_wallpaper_set_vui_live_wallpaper_setting(U8 data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 error;
    S32 result;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_PRINT(MOD_MMI_COMMON_APP, MMI_COMMON_TRC_G7_SETTING, "[Wallpaper.c] Set VUI Live wallpaper (%d)", data);
    if (data >= VAPP_HS_WALLPAPER_LAST_ITEM)
	{
	    return MMI_FALSE;
	}
    result = WriteValue(NVRAM_PHNSET_LIVE_WALLPAPER, &data, DS_BYTE, &error);
    if (result == -1)
	{
	    return MMI_FALSE;
	}
    return MMI_TRUE;
}
#endif

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_get_vui_live_wallpaper_setting
 * DESCRIPTION
 *  Get VUI Live wallpaper setting 
 * PARAMETERS
 *  void
 * RETURNS
 *  U8
 *****************************************************************************/
U8 mmi_phnset_wallpaper_get_vui_live_wallpaper_setting(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 error; 
    U8 data;
    /* This enum has the same sequence as the string */
    U8 live_wallpaper_enum[] = {
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperWide, 
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_WAVE__            
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperWave,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_SPANGLE__
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperSpangleGold,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_CHIPSET__
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperChipset,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_COMET__
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperComet,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_SPACE__
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperSpace,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_MATRIX__
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperMatrix,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_WILDWORLD__
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperWildWorld,
#endif
#ifdef __MMI_VUI_HOMESCREEN_LIVE_WALLPAPER_FIREFLY__
        VAPP_HS_WALLPAPER_ENUM_VappHsWallpaperFirefly,
#endif
        VAPP_HS_WALLPAPER_LAST_ITEM // For ending
        };
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ReadValue(NVRAM_PHNSET_LIVE_WALLPAPER, &data, DS_BYTE, &error);  
    if (data >= VAPP_HS_WALLPAPER_LAST_ITEM)
	{
        MMI_PRINT(MOD_MMI_COMMON_APP, MMI_COMMON_TRC_G7_SETTING, "[Wallpaper.c] Reset live wallpaper setting");
	    data = 0;
        WriteValue(NVRAM_PHNSET_LIVE_WALLPAPER, &data, DS_BYTE, &error);
	}    
    MMI_PRINT(MOD_MMI_COMMON_APP, MMI_COMMON_TRC_G7_SETTING, "[Wallpaper.c] Get VUI Live wallpaper (%d)", data);    
    return live_wallpaper_enum[data];
}
#endif

#ifdef __MMI_FILE_MANAGER__
/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wallpaper_entry_fmgr
 * DESCRIPTION
 *  Entry file resource selection screen of wallpaper, for external used. 
 * PARAMETERS
 *  parent_gid  :   [IN]    Group ID of parent
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_wallpaper_entry_fmgr(MMI_ID parent_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phnset_cntx_p->wpss_type = MMI_PHNSET_TYPE_WP;
    EntryPhnsetWallpaperFmgr(parent_gid);
}
#endif /* __MMI_FILE_MANAGER__ */

/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_enter_switch_screen
 * DESCRIPTION
 *  Create a new screen and delete old one to handle screen switch 
 * PARAMETERS
 *  
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_phnset_enter_switch_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MMI_ID new_scrn_id;
    MMI_ID group_id;
    MMI_ID curr_scrn_id = mmi_frm_scrn_get_active_id();
    FuncPtr enter_func;
    FuncPtr exit_func;
    MMI_BOOL close_scrn_flag = MMI_FALSE;
    MMI_BOOL ret;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch(g_phnset_cntx_p->wpss_type)
    {
    case MMI_PHNSET_TYPE_WP:
#ifdef __MMI_SUB_WALLPAPER__
    case MMI_PHNSET_TYPE_SUB_WP:
#endif
        group_id = GRP_ID_WALLPAPER_SYSTEM;
        /* There is already a screen */
        if (curr_scrn_id == SCR_WALLPAPER_VIEW || curr_scrn_id == SCR_WALLPAPER_VIEW_2)
    	{
            close_scrn_flag = MMI_TRUE;
            new_scrn_id = (curr_scrn_id == SCR_WALLPAPER_VIEW) ? SCR_WALLPAPER_VIEW_2 : SCR_WALLPAPER_VIEW;
    	}
        /* First enter this screen */
        else
        {
            new_scrn_id = SCR_WALLPAPER_VIEW;
        }
        enter_func = EntryPhnsetWallpaperSysView;
        exit_func = ExitPhnsetWallpaperSysView;
        break;

    case MMI_PHNSET_TYPE_SS:
        group_id = GRP_ID_SCREENSAVER_SYSTEM;
        /* There is already a screen */
        if (curr_scrn_id == SCR_SCREENSAVER_VIEW || curr_scrn_id == SCR_SCREENSAVER_VIEW_2)
    	{
            close_scrn_flag = MMI_TRUE;
            new_scrn_id = (curr_scrn_id == SCR_SCREENSAVER_VIEW) ? SCR_SCREENSAVER_VIEW_2 : SCR_SCREENSAVER_VIEW;
    	}
        /* First enter this screen */
        else
        {
            new_scrn_id = SCR_SCREENSAVER_VIEW;
        }
        enter_func = EntryPhnsetScrSvrSysView;
        exit_func = ExitPhnsetScrSvrSysView;
        break;   

#ifdef __MMI_POWER_ON_OFF_DISPLAY__
    case MMI_PHNSET_TYPE_PWRON:
        group_id = GRP_ID_POWER_ON_OFF_SYSTEM;
        /* There is already a screen */
        if (curr_scrn_id == SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW || curr_scrn_id == SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW_2)
    	{
            close_scrn_flag = MMI_TRUE;
            new_scrn_id = (curr_scrn_id == SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW) ? SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW_2 : SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW;
    	}
        /* First enter this screen */
        else
        {
            new_scrn_id = SCR_ID_PHNSET_POWER_ON_SYSTEM_VIEW;
        }
        enter_func = EntryPhnsetPwrOnOffSysView;
        exit_func = ExitPhnsetPwrOnOffSysView;
        break;           

        
    case MMI_PHNSET_TYPE_PWROFF:
        group_id = GRP_ID_POWER_ON_OFF_SYSTEM;
        /* There is already a screen */
        if (curr_scrn_id == SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW || curr_scrn_id == SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW_2)
    	{
            close_scrn_flag = MMI_TRUE;
            new_scrn_id = (curr_scrn_id == SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW) ? SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW_2 : SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW;
    	}
        /* First enter this screen */
        else
        {
            new_scrn_id = SCR_ID_PHNSET_POWER_OFF_SYSTEM_VIEW;
        }
        enter_func = EntryPhnsetPwrOnOffSysView;
        exit_func = ExitPhnsetPwrOnOffSysView;
        break;         
#endif /* __MMI_POWER_ON_OFF_DISPLAY__ */
    }
    /* If it is back from other screen, create new and close old will behave incorrectly */
    if (mmi_frm_is_in_backward_scenario())
	{
	    ret = mmi_frm_scrn_enter(group_id, curr_scrn_id, exit_func, enter_func, MMI_FRM_UNKNOW_SCRN);
	}
    else
    {
        ret = mmi_frm_scrn_enter(group_id, new_scrn_id, exit_func, enter_func, MMI_FRM_UNKNOW_SCRN);
        if (close_scrn_flag)
    	{
    	    mmi_frm_scrn_close(group_id, curr_scrn_id);
    	}
    }
    return ret;
}


#ifdef __MMI_FILE_MANAGER__
void mmi_fmgr_to_wallpaper_hdlr(mmi_menu_id item_id, const WCHAR* filepath, const srv_fmgr_fileinfo_struct* fileinfo)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    PhnsetWallpaperForwardFromFmgr((void*)filepath, fileinfo->type);
}

#ifdef __MMI_SUB_WALLPAPER__		
void mmi_fmgr_to_sub_wallpaper_hdlr(mmi_menu_id item_id, const WCHAR* filepath, const srv_fmgr_fileinfo_struct* fileinfo)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    PhnsetSubWallpaperForwardFromFmgr((void*)filepath, fileinfo->type);    
}
#endif


/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_display_use_as_enabler
 * DESCRIPTION
 *  Enabler for file manager use as wallpaper, screen saver, power on/off display menu 
 * PARAMETERS
 *  
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phnset_display_use_as_enabler(mmi_menu_id item_id, const WCHAR* filepath, const srv_fmgr_fileinfo_struct* fileinfo)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    phnset_wpss_type_enum check_type = 0;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (item_id)
	{
	case MENU_ID_FMGR_FWD_WALLPAPER:
        check_type = MMI_PHNSET_TYPE_WP;
        break;
#ifdef __MMI_SUB_WALLPAPER__        
	case MENU_ID_FMGR_FWD_SUB_WALLPAPER:
        check_type = MMI_PHNSET_TYPE_SUB_WP;
        break;
#endif        
    case MENU_ID_FMGR_FWD_SCREENSAVER:
        check_type = MMI_PHNSET_TYPE_SS;
        break;
#ifdef __MMI_POWER_ON_OFF_DISPLAY__        
    case MENU_ID_FMGR_FWD_POWER_ON:
        check_type = MMI_PHNSET_TYPE_PWRON;
        break;
        
    case MENU_ID_FMGR_FWD_POWER_OFF:
        check_type = MMI_PHNSET_TYPE_PWROFF;
		break;
#endif        
	default:
		break;
	}
    if (!mmi_phnset_display_check_file_type(fileinfo->type, check_type))
	{
	    mmi_frm_hide_menu_item(item_id);
	}    
}


#endif /* __MMI_FILE_MANAGER__ */

#ifdef __MMI_DSM_NEW__
// 如果编译不过，把这段代码位置往后放
S32 mr_setting_wallpaper_adp(S16* path)
{
#if (__MR_CFG_VAR_MTK_VERSION__ >= 0x11B1132)

	S16 error;
	    
	mmi_wcscpy(g_mmi_wallpaper_user_file.file_name, path);
	g_mmi_wallpaper_id = 0;
	mmi_dispchar_set_img_id(NVRAM_FUNANDGAMES_SETWALLPAPER, &g_mmi_wallpaper_id);

	idle_screen_wallpaper_name = (S8*)g_mmi_wallpaper_user_file.file_name;
	idle_screen_wallpaper_name_original = (S8*)g_mmi_wallpaper_user_file.file_name;
	idle_screen_wallpaper_name_original = (S8*)g_mmi_wallpaper_user_file.file_name;

	SetIdleScreenWallpaperName((UI_string_type)g_mmi_wallpaper_user_file.file_name);

	WriteRecord(NVRAM_EF_WALLPAPER_FILENAME_LID, 1, &g_mmi_wallpaper_user_file, sizeof(mmi_setting_display_cache_file_nvram_struct), &error);        
    
#else
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 path_ucs2[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
    S16 drive;
    U8 process_result;
    S32 ret;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_022);

    g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP;

    phnset_dispchar_strp = (S8*)path;

    drive = SRV_FMGR_PUBLIC_DRV;

    process_result = mmi_phnset_wallpaper_prepare_folder(drive);
    if( process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return FALSE;
    }

    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        g_phnset_wallpaper_default_file_1.is_short = 0;
        g_phnset_wallpaper_default_file_2.is_short = 0;        
//        phnset_wpss_default_file_1.isWPShort = 0;
//        phnset_wpss_default_file_2.isWPShort = 0;
    }
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
    {
        g_phnset_screensaver_default_file_1.is_short = 0;
        g_phnset_screensaver_default_file_2.is_short = 0; 
//         g_phnset_screensaver_default_file_1.is_dirty = 0;
//        phnset_wpss_default_file_2.isSSShort = 0;
    }

    mmi_phnset_init_default_file();
    
    mmi_phnset_del_dirty_file();

    /* disk free space is OK or old file size more */
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_029);

    process_result = mmi_phnset_wallpaper_prepare_file_path(path_ucs2);
    if(process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return FALSE;
    }

    process_result = mmi_phnset_wallpaper_check_disk(drive);    
    if(process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return FALSE;
    }

        /* use FMT to copy a file */
        ret = srv_fmgr_fs_copy((WCHAR*)phnset_dispchar_strp, (WCHAR*)path_ucs2);

	if (ret < 0) return FALSE;

	mmi_phnset_copy_wpss_save_setting((U8*)phnset_dispchar_strp);

	phnset_dispchar_strp = NULL;
#endif
    return TRUE;	
}

S32 mr_setting_screensaver_adp(S16* path)
{
#if (__MR_CFG_VAR_MTK_VERSION__ >= 0x11B1132)

#else
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 path_ucs2[(SRV_FMGR_PATH_MAX_LEN + 1) * 2];
    S16 drive;
    U8 process_result;
    S32 ret;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_022);

    g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS;

    phnset_dispchar_strp = (S8*)path;

    drive = SRV_FMGR_PUBLIC_DRV;

    process_result = mmi_phnset_wallpaper_prepare_folder(drive);
    if( process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return FALSE;
    }

    if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_WP)
    {
        g_phnset_wallpaper_default_file_1.is_short = 0;
        g_phnset_wallpaper_default_file_2.is_short = 0;        
//        phnset_wpss_default_file_1.isWPShort = 0;
//        phnset_wpss_default_file_2.isWPShort = 0;
    }
    else if (g_phnset_cntx_p->wpss_type == MMI_PHNSET_TYPE_SS)
    {
        g_phnset_screensaver_default_file_1.is_short = 0;
        g_phnset_screensaver_default_file_2.is_short = 0; 
//         g_phnset_screensaver_default_file_1.is_dirty = 0;
//        phnset_wpss_default_file_2.isSSShort = 0;
    }

    mmi_phnset_init_default_file();
    
    mmi_phnset_del_dirty_file();

    /* disk free space is OK or old file size more */
    MMI_TRACE(MMI_COMMON_TRC_G7_SETTING, MMI_WALLPAPER_TRACE_029);

    process_result = mmi_phnset_wallpaper_prepare_file_path(path_ucs2);
    if(process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return FALSE;
    }

    process_result = mmi_phnset_wallpaper_check_disk(drive);    
    if(process_result != PHNSET_WP_SS_SET_NO_ERROR)
    {
        return FALSE;
    }

        /* use FMT to copy a file */
        ret = srv_fmgr_fs_copy((WCHAR*)phnset_dispchar_strp, (WCHAR*)path_ucs2);

	if (ret < 0) return FALSE;

	mmi_phnset_copy_wpss_save_setting((U8*)phnset_dispchar_strp);

	phnset_dispchar_strp = NULL;
#endif
    return TRUE;	
}

#endif/*__MMI_DSM_NEW__*/

#ifdef __MMI_USB_SUPPORT__
#ifdef __MMI_USB_SPLIT_SUPPORT__
/*****************************************************************************
 * FUNCTION
 *  mmi_phnset_wp_ss_pwr_disp_ms_hdlr
 * DESCRIPTION
 *  Handler for wallpaper, screen saver and power on off display when entering
 *  or exitting USB mass storage mode 
 * PARAMETERS
 *  
 * RETURNS
 *  mmi_ret
 *****************************************************************************/
mmi_ret mmi_phnset_wp_ss_pwr_disp_ms_hdlr(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __USB_IN_NORMAL_MODE__    
    switch (evt->evt_id)
	{
        /* Entering Mass Storage mode */
	case EVT_ID_USB_ENTER_MS_MODE:
        PhnsetWPUseDefault();               /* suspend wallpaper */
        PhnsetSSUseDefault();               /* suspend screensaver */
#ifdef __MMI_POWER_ON_OFF_DISPLAY__
        PhnsetPwrOnOffUseDefault();         /* suspend power on/off disp. */
#endif 		
		break;
        /* Exiting Mass Storage mode */
    case EVT_ID_USB_EXIT_MS_MODE:
        PhnsetReadWallpaper();              /* resume wallpaper from secondary flash */
        PhnsetReadNvramScrSvrSettings();    /* resume screensaver from secondary flash */
#ifdef __MMI_POWER_ON_OFF_DISPLAY__
        PhnsetReadPwrOnOffDisp();           /* resume power on/off disp. from secondary flash */
#endif         
        break;
	default:
		break;
	}
#endif    
    return MMI_RET_OK;
}
#endif /* __MMI_USB_SPLIT_SUPPORT__ */
#else /* __MMI_USB_SUPPORT__ */
mmi_ret mmi_phnset_wp_ss_pwr_disp_ms_hdlr(mmi_event_struct *evt)
{
    return MMI_RET_OK;
}
#endif /* __MMI_USB_SUPPORT__ */
